Dynamic Copyright
as bns_dynamic_copyright, dynamic_copyright, get_posts, WordPress
At the bottom of most blogs you will find the commonplace copyright notice that may look something like this:
Copyright © 2010 WP First Aid All rights reserved.
Which begs the question, what about those posts made before the year 2010? This is where a dynamic copyright function would come in very handy. It would be more correct to have this display in the footer:
Copyright © 2009-2010 WP First Aid All rights reserved.
Most WordPress themes will include, at a minimum, code that will generate a current year copyright statement, perhaps something along these lines:
<?php _e( 'Copyright © ' ); ?> <?php echo date( 'Y' ); ?> <strong> <?php bloginfo( 'name' ); ?> </strong> <?php _e( 'All rights reserved.' ); ?>
To make this code into a function and add some dynamics lets start with a simple PHP construct:
function dynamic_copyright() {
// code goes here
}
To get the first year a post was written on the blog we need to find the first post. This can be done with this code snippet:
$all_posts = get_posts( 'order=ASC' ); $first_post = $all_posts[0]; $first_date = $first_post->post_date_gmt;
We started by getting all of the posts with the get_posts() function. We assigned the first post, which is found at index 0 (zero) to its own variable. Then we assign that post’s date (in GMT) to its own variable.
We now have isolated the date of the first post on the blog and can perform further operations on it. The basic dynamic part of the function is complete. If the first post is removed and the “new” first post has a different date, then the above snippet will simply use the new post’s date.
The balance of the function is only a slight modification of the original “minimum” sample code from above:
_e( 'Copyright © ' ); echo substr( $first_date, 0 ,4 ) . "-" . date( 'Y' ); echo ' <strong>' . get_bloginfo( 'name' ) . '</strong> '; _e( 'All rights reserved.' );
The key is highlighted at line 6. We echo, or display, the first four characters of the $first_date string which is the year; add a hyphen; and, then call a standard PHP function to add the current year as a four digit representation.
Here is the entire dynamic_copyright() function, including comments:
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.' );
}
Of course, this function is compliments of BuyNowShop.com and has their customary bns prefix as it will be appearing in all of their themes.
Just like I did, you can copy and paste the entire sample bns_dynamic_copyright() code above into your theme’s functions.php file; then, replace the code in your theme’s footer.php file that generates your old static copyright notice with this line of code:
<?php bns_dynamic_copyright(); ?>
Your theme will now display a dynamic copyright notice as you continue your writings for many years to come. Congratulations!
Your Username Can Be Changed
as change, how-to, login, username, WordPress
Changing a username in WordPress cannot be done within the WordPress interfaces, but it is still easy to do … providing you have access to the WordPress database.
NB: This tip is offered under the premise you are using a self-hosted installation of WordPress and your web host provider has installed the cPanel application to allow you to manage your web site.
Let’s start …
- Access the cPanel for your web site; and, locate the phpMyAdmin applet, it is generally found in the Databases section.
- Start phpMyAdmin.
- Locate and access your WordPress database.
- Find the wp_users table
Next, click on the left most icon to browse the users in the wp_users table.
Then, click on the “pencil” icon beside the user you wish to edit. This will display the screen we will be using to change the username.
Now, edit the user_login (and the user_nicename) to your new login username. Click on the “GO” button in the bottom right corner (not shown in the image) of the edit screen. Voila!
You can now change the username in a WordPress self-hosted installation. Well Done!
PS: Applying this technique using other methods to access the database is possible, this one only deals with using the cPanel / phpMyAdmin combination.
PPS: Remember to make back-ups! Always!









