Last updated on September 25, 2023

Add a Custom Copyright Notice to the Footer

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Ensure legal compliance with copyrights.

To add a custom copyright notice to the footer of your WordPress website, you can use the wp_footer action hook along with a custom PHP function. This allows you to easily insert your own copyright text without modifying the theme files directly.

Here’s an example code snippet that demonstrates how to achieve this:

function wpsnippets_custom_copyright_notice() {
    echo '<div class="copyright">© ' . date( 'Y' ) . ' Your Website Name. All rights reserved.</div>';
}
add_action( 'wp_footer', 'wpsnippets_custom_copyright_notice' );

In this code snippet, we define a custom PHP function called wpsnippets_custom_copyright_notice. Inside the function, we use the echo statement to output the desired copyright notice. The date( 'Y' ) function is used to dynamically display the current year.

Finally, we use the add_action function to hook our custom function to the wp_footer action. This ensures that our copyright notice is displayed in the footer of every page on your WordPress site.

You can customize the copyright text and HTML markup as per your requirements by modifying the echo statement within the wpsnippets_custom_copyright_notice function.

Examples

Example 1: Adding a custom copyright notice to the footer using a shortcode

This use case demonstrates how to add a custom copyright notice to the footer of a WordPress website using a shortcode. The shortcode allows you to easily insert the copyright notice anywhere in your content.

function wpsnippets_copyright_notice_shortcode() {
    return '© ' . date( 'Y' ) . ' Your Website Name. All rights reserved.';
}
add_shortcode( 'copyright', 'wpsnippets_copyright_notice_shortcode' );

Explanation:

  • The wpsnippets_copyright_notice_shortcode function returns the copyright notice text, including the current year and your website name.
  • The add_shortcode function is used to register the shortcode. The first parameter is the shortcode name, and the second parameter is the callback function that generates the shortcode output.
  • After adding this code snippet, you can use [copyright] shortcode to display the copyright notice.

Example 2: Adding a custom copyright notice to the footer using a filter

This use case demonstrates how to add a custom copyright notice to the footer of a WordPress website using a filter. The filter allows you to modify the footer content before it is displayed.

function wpsnippets_custom_copyright_notice( $content ) {
    $copyright_notice = '© ' . date( 'Y' ) . ' Your Website Name. All rights reserved.';
    return $content . '<p>' . $copyright_notice . '</p>';
}
add_filter( 'wp_footer', 'wpsnippets_custom_copyright_notice' );

Explanation:

  • The wpsnippets_custom_copyright_notice function appends the copyright notice to the existing footer content.
  • The add_filter function is used to hook into the wp_footer action, which is triggered when the footer is being generated. The function name is passed as the second parameter.

Example 3: Adding a custom copyright notice to the footer using a theme template file

This use case demonstrates how to add a custom copyright notice to the footer of a WordPress website by modifying the theme’s template file.

function wpsnippets_custom_footer_copyright() {
    echo '© ' . date( 'Y' ) . ' Your Website Name. All rights reserved.';
}

Explanation:

  • The wpsnippets_custom_footer_copyright function echoes the copyright notice directly in the template file.
  • This code can be added to the footer.php file of your theme, typically located in the theme’s root directory. The copyright notice will be displayed wherever the get_footer function is called in your theme’s template files.
Last updated on September 25, 2023. Originally posted on October 17, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *