A while back I wrote an article about a function to generate a dynamic copyright to display in themes. Although I imagine the function can be adapted to be used elsewhere, the original intent was to place the function call in the footer of any given theme.
The function itself can be found in all the themes currently available from Cais at BuyNowShop.com via the WordPress Extend Themes repository. There have been a few minor changes to the function since it was introduced; and, it is just recently undergoing much more dramatic changes.
That being the case, I thought this would be a great opportunity to revisit the function and discuss what has changed since the last time I wrote about it here.
// Start BNS Dynamic Copyright if ( ! function_exists( 'bns_dynamic_copyright' ) ) { function bns_dynamic_copyright( $args = '' ) { $initialize_values = array( 'start' => '', 'copy_years' => '', 'url' => '', 'end' => '' ); $args = wp_parse_args( $args, $initialize_values ); /* Initialize the output variable to empty */ $output = ''; /* Start common copyright notice */ empty( $args['start'] ) ? $output .= sprintf( __('Copyright') ) : $output .= $args['start']; /* Calculate Copyright Years; and, prefix with Copyright Symbol */ if ( empty( $args['copy_years'] ) ) { /* 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; /* First post year versus current year */ $first_year = substr( $first_date, 0, 4 ); if ( $first_year == '' ) { $first_year = date( 'Y' ); } /* Add to output string */ if ( $first_year == date( 'Y' ) ) { /* Only use current year if no posts in previous years */ $output .= ' © ' . date( 'Y' ); } else { $output .= ' © ' . $first_year . "-" . date( 'Y' ); } } else { $output .= ' © ' . $args['copy_years']; } /* Create URL to link back to home of website */ empty( $args['url'] ) ? $output .= ' <a href="' . home_url( '/' ) . '" title="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '" rel="home">' . get_bloginfo( 'name', 'display' ) .'</a> ' : $output .= ' ' . $args['url']; /* End common copyright notice */ empty( $args['end'] ) ? $output .= ' ' . sprintf( __('All rights reserved.') ) : $output .= ' ' . $args['end']; /* Construct and sprintf the copyright notice */ $output = sprintf( __('<span id="bns-dynamic-copyright"> %1$s </span><!-- #bns-dynamic-copyright -->'), $output ); $output = apply_filters( 'bns_dynamic_copyright', $output, $args ); echo $output; } } // End BNS Dynamic Copyright
What’s changed:
- A `function_exists` conditional check has been added
- Better internationalization string formating has been applied.
- Default arguments have been set to generate a common notice.
- The `apply_filters` function has been implemented to allow for easier customization.
Also to note, the defaults are now written slightly different than the orginal generated copyright notice structure. The following are the current defaults:
- ‘start’ => “Copyright”
- ‘copy_years’ => the copyright symbol + the dynamically generated years with published posts
- ‘url’ => points to the top level domain with the web site title as anchor text
- ‘end’ => “All Rights Reserved.”
All of these paramters are now easily customized using the common WordPress structure, for example:
bns_dynamic_copyright( 'start=Mine, All Mine!&end=This means you, scrapers!' );
… would produce the following for this site (as of this writing):
Mine, All Mine! © 2009-2011 WP First Aid This means you, scrapers!
Of course, the above may not be appropriate for your own website … or maybe it is.
All the same, feel free to implement this updated function; and, don’t forget to look for it in the next releases of themes from BuyNowShop.com
Enjoy!