{"id":3752,"date":"2009-09-04T07:13:02","date_gmt":"2009-09-04T14:13:02","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3752"},"modified":"2016-12-29T15:02:48","modified_gmt":"2016-12-29T22:02:48","slug":"automatic-copyright-year","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/php\/automatic-copyright-year\/","title":{"rendered":"Automatic Copyright Year"},"content":{"rendered":"

Current year only<\/h4>\n
&copy; <?php echo date(\"Y\"); ?><\/code><\/pre>\n

With start year<\/h4>\n
&copy; 2008-<?php echo date(\"Y\"); ?><\/code><\/pre>\n

Start date with error protection<\/h4>\n
<?php function auto_copyright($year = 'auto'){ ?>\r\n   <?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>\r\n   <?php if(intval($year) == date('Y')){ echo intval($year); } ?>\r\n   <?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>\r\n   <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>\r\n<?php } ?><\/code><\/pre>\n

Usage:<\/p>\n

<?php auto_copyright(); \/\/ 2011?>\r\n\r\n<?php auto_copyright(\"2010\");  \/\/ 2010 - 2017 ?><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Current year only &copy; <?php echo date(“Y”); ?> With start year &copy; 2008-<?php echo date(“Y”); ?> Start date with error protection <?php function auto_copyright($year = ‘auto’){ ?> <?php if(intval($year) == ‘auto’){ $year = date(‘Y’); } ?> <?php if(intval($year) == date(‘Y’)){ echo intval($year); } ?> <?php if(intval($year) < date(‘Y’)){ echo intval($year) . ‘ – ‘ . […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3233,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":5726,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/validate-age\/","url_meta":{"origin":3752,"position":0},"title":"Validate Age","date":"February 23, 2010","format":false,"excerpt":"This snippet presupposed an HTML form with and ID of \"age-form\" and three inputs (text or select) with the IDs \"day\", \"month\", and \"year\" respectively. $(\"#age-form\").submit(function(){ var day = $(\"#day\").val(); var month = $(\"#month\").val(); var year = $(\"#year\").val(); var age = 18; var mydate = new Date(); mydate.setFullYear(year, month-1, day);\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16456,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/year-shortcode\/","url_meta":{"origin":3752,"position":1},"title":"Year Shortcode","date":"March 8, 2012","format":false,"excerpt":"For the functions.php file: function year_shortcode() { $year = date('Y'); return $year; } add_shortcode('year', 'year_shortcode'); Usage Use [year] in your posts.","rel":"","context":"With 19 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":249342,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/replacements-setinterval-using-requestanimationframe\/","url_meta":{"origin":3752,"position":2},"title":"Replacements for setInterval Using requestAnimationFrame","date":"December 26, 2016","format":false,"excerpt":"When it comes to animation, we're told that setInterval is a bad idea. Because, for example, the loop will run regardless of anything else going on, rather than politely yielding like requestAnimationFrame will. Also some browsers might \"play catchup\" with a setInterval loop, where an inactive tab might have been\u2026","rel":"","context":"With 1 comment","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":20338,"url":"https:\/\/css-tricks.com\/lodge\/artists-website\/018-footer\/","url_meta":{"origin":3752,"position":3},"title":"#018 – Footer","date":"March 3, 2013","format":false,"excerpt":"This will be about the simplest footer ever on a site. It will be a copyright symbol with Jeff's name (It's always nice, I think, to have the name of the site in the footer in plain text for easy copy-and-paste) and social media links. The year will auto update\u2026","rel":"","context":"With 2 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5465,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/error-free-firebug-logging\/","url_meta":{"origin":3752,"position":4},"title":"Error-Free Console Logging","date":"February 2, 2010","format":false,"excerpt":"var Fb = {}; \/\/An empty object literal for holding the function Fb.log = function(obj, consoleMethod) { if (window.console && window.console.firebug && window.console.firebug.replace(\/^\\s\\s*\/, '').replace(\/\\s\\s*$\/, '') !== '') { if (typeof consoleMethod === \"string\" && typeof console[consoleMethod] === \"function\") { console[consoleMethod](obj); } else { console.log(obj); } } } If you leave\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3494,"url":"https:\/\/css-tricks.com\/snippets\/php\/php-date-parameters\/","url_meta":{"origin":3752,"position":5},"title":"PHP Date Parameters","date":"August 21, 2009","format":false,"excerpt":"format character Description Example returned values Day --- --- d Day of the month, 2 digits with leading zeros 01 to 31 D A textual representation of a day, three letters Mon through Sun j Day of the month without leading zeros 1 to 31 l (lowercase 'L') A full\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3752"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3752"}],"version-history":[{"count":5,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3752\/revisions"}],"predecessor-version":[{"id":249458,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3752\/revisions\/249458"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3233"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3752"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}