{"id":46639,"date":"2026-10-10T17:17:33","date_gmt":"2026-10-10T17:17:33","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46639"},"modified":"2026-10-10T17:17:33","modified_gmt":"2026-10-10T17:17:33","slug":"wordpress-current-year-shortcode","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wordpress-current-year-shortcode\/","title":{"rendered":"WordPress Current Year Shortcode for Copyright Footers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A WordPress current year shortcode saves you from editing the copyright line every January. Put <code>&#91;current_year&#93;<\/code> in the footer once and it always shows the right year.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This version also handles the common &#8220;\u00a9 2019\u20132026&#8221; format: <code>&#91;current_year from=\"2019\"&#93;<\/code> prints the start year, a dash and the current year.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\nadd_shortcode( 'current_year', 'dpc_current_year_shortcode' );\n\n\/**\n * &#91;current_year&#93; prints the current year.\n * &#91;current_year from=\"2019\"&#93; prints a range such as \"2019\u20132026\".\n *\/\nfunction dpc_current_year_shortcode( $atts ) {\n\t$atts = shortcode_atts( array( 'from' =&gt; '' ), $atts, 'current_year' );\n\t$year = (int) wp_date( 'Y' );\n\t$from = absint( $atts&#91;'from'&#93; );\n\n\tif ( $from &gt; 0 &amp;&amp; $from &lt; $year ) {\n\t\treturn esc_html( $from . '\u2013' . $year );\n\t}\n\n\treturn esc_html( (string) $year );\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> ships this snippet in its One-Click Import library. To add it by hand:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In wp-admin go to <strong>Scripts Organizer \u2192 Code Blocks \u2192 Add New<\/strong> and give the block a title.<\/li>\n\n\n<li><strong>Script location<\/strong>: PHP.<\/li>\n\n\n<li><strong>Trigger location<\/strong>: Everywhere. The shortcode then exists on every request that may render it, including block editor previews that go through the REST API.<\/li>\n\n\n<li><strong>Action hook<\/strong>: leave it empty. The code only registers filters and actions, so it can run while plugins load.<\/li>\n\n\n<li>Paste the snippet into the PHP editor, enable the block and publish it.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The same code also works unchanged in a small plugin or an mu-plugin file in <code>wp-content\/mu-plugins\/<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>add_shortcode()<\/code> registers <code>&#91;current_year&#93;<\/code>. The callback returns the string; a shortcode must never <code>echo<\/code>, or the year shows up above the content instead of in place.<\/li>\n\n\n<li><code>wp_date( 'Y' )<\/code> uses the timezone from <strong>Settings \u2192 General<\/strong>. WordPress sets PHP&#8217;s default timezone to UTC, so the older <code>date( 'Y' )<\/code> ignores your site timezone and can switch the year hours early or late on New Year&#8217;s Eve.<\/li>\n\n\n<li><code>shortcode_atts()<\/code> fills in missing attributes, and <code>absint()<\/code> turns <code>from<\/code> into a positive integer, so <code>from=\"abc\"<\/code> is ignored instead of printed.<\/li>\n\n\n<li>If <code>from<\/code> is the current year or later, only the current year prints, so you never see &#8220;2026\u20132026&#8221;.<\/li>\n\n\n<li><code>esc_html()<\/code> escapes the output before it reaches the page.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Use it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In a block theme, open the footer template part in the Site Editor, add a <strong>Shortcode<\/strong> block and type <code>\u00a9 &#91;current_year from=\"2019\"&#93; Your Company<\/code>. In a classic theme, a Shortcode block in a footer widget area works the same way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For a different format, change <code>'Y'<\/code> to another <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/www.php.net\/manual\/en\/datetime.format.php\">PHP date format<\/a> character, for example <code>'y'<\/code> for a two-digit year.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Full-page caching serves stored HTML. The year changes when the cache is rebuilt; if you cache pages for weeks, clear the cache on 1 January.<\/li>\n\n\n<li>The tag <code>current_year<\/code> has no prefix, because sites already use it in their footers. If another plugin registers the same shortcode, the one added last wins; rename the tag in <code>add_shortcode()<\/code> if the output looks different from what you expect.<\/li>\n\n\n<li>Shortcodes are not processed in the site title, menu labels or post titles unless the theme runs <code>do_shortcode()<\/code> there.<\/li>\n\n\n<li>For another small shortcode in the same style, see <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/post-reading-time-shortcode\/\">Post reading time shortcode<\/a>.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>A WordPress shortcode that prints the current year, or a range like 2019\u20132026, so the copyright line in your footer never shows last year again.<\/p>\n","protected":false},"author":1,"featured_media":46640,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"WordPress Current Year Shortcode for Copyright Footers","description":"A WordPress shortcode that prints the current year, or a range like 2019\u20132026, so the copyright line in your footer never shows last year again."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[3],"tags":[187,188,186,185],"dpc_library":[204],"class_list":["post-46639","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-copyright","tag-date","tag-footer","tag-shortcode"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46639"}],"version-history":[{"count":2,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46639\/revisions"}],"predecessor-version":[{"id":46654,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46639\/revisions\/46654"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46640"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46639"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46639"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}