Adding Dynamic Copyrights

Posted by Edward Caissie on February 16, 2010 in News, WordPress |

We will be adding to all of our themes our latest optimization, the bns_dynamic_copyright() function.

WPFirstAid.com recently wrote a post covering the inclusion of this dynamic copyright function into most any theme. This added functionality will be included with the next update of each of our themes.

Using the get_post() function, bns_dynamic_copyright() essentially finds the blog’s first post; makes note of its date; then creates a copyright notice that takes into account the year in the date of the first (read: oldest) post to recognize the lifetime of the blog.

Here is the code to be placed in the functions.php file:

function bns_dynamic_copyright() {
  /* Get all posts */
  $all_posts = get_posts('post_status=publish&order=ASC');
  /* Get first post */
  $first_post = $all_posts[0];
  /* Get date of first post */
  $first_date = $first_post->post_date_gmt;

  /* Display common footer copyright notice */
  _e('Copyright © ');
  /* Display first post year and current year */
  if ( substr($first_date,0,4) == date(Y) ) {
  /* Only display current year if no posts in previous years */
    echo date(Y);
  } else {
    echo substr($first_date,0,4) . "-" . date(Y);
  /* Display blog name from 'General Settings' page */
  echo ' <strong>' . get_bloginfo('name') . '</strong> ';
  _e('All rights reserved.');

… and here is the line of code to replace the old static copyright notice:

<?php bns_dynamic_copyright(); ?>

Tags: , , ,

1 Comment

Leave a Reply

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

Copyright © 2009-2017 BuyNowShop All rights reserved.
This site is using the Custom Child-Theme, v1.0.3, on top of
the Parent-Theme Desk Mess Mirrored, v2.5, from BuyNowShop.com