How to Add a Dynamic Copyright Date in WordPress Footer

2 min read

How to Add a Dynamic Copyright Date or Year in WordPress Footer

Your web site is your reflection to the web world. It’s answerable for the impression you need to give your viewers. Some widespread errors can damage your persona. An outdated copyright date is without doubt one of the widespread errors that many of the site owners do. An outdated copyright date or an expired providing calls all of the information on an internet site into query as to its correctness.

Different methods to Add a Dynamic Copyright Date

Simple PHP technique

This is the best technique for displaying dynamic copyright date in your web site. Just put this code in your PHP file and present the present 12 months in your web site.

Copyright <?php echo date('Y'); ?> My Company.

 

JavaScript Method

This is an one other easiest technique for displaying dynamic copyright date in your web site. Just use this JavaScript code and present the present 12 months in your web site.

 

var theYear = document.createElement( 'div' );
theYear.classList.add( 'the-year' );
theYear.textContent = 'Copyright ' + new Date().getFullYear() + ' My Company.';
document.body.appendChild( theYear );

 

Source: GitHub

From Year to present Year

If you need one thing extra elaborate that may take the 12 months of the earliest submit you must the most recent submit you’ve gotten, you are able to do this by including the next operate in your functions.php file.

function smallenvelop_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = '';
if($copyright_dates) {
$copyright = "&copy; " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}

Then open your theme’s footer.php file and add the next code the place you need to show the date:

 

<?php echo smallenvelop_copyright(); ?>

 

Source: wpmudev

With the assistance of Plugins

If you don’t need to cope with the codes, right here is the subsequent resolution for you. WordPress repository has many plugins for displaying dynamic copyright date in your web site. Here I’m itemizing a number of the WordPress plugins that may provide help to.

Current Year and Copyright Shortcodes

Auto Copyright

Dynamic Dates

Copyright Shortcodes

InstallActivateGo Copyright Current Date Shortcodes

 

Auto Copyright

 

 

 

Copyright Shortcodes

 

If you like you can also check wordpress best plugins for syntax highlighter

 

Related Post  Connection is Not Private Fix

Leave a Reply

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

CommentLuv badge