Automatic Copyright Year

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) . ' - ' . date('Y'); } ?>
   <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
<?php } ?>


<?php auto_copyright(); // 2011?>

<?php auto_copyright("2010");  // 2010 - 2017 ?>


  1. User Avatar
    Permalink to comment#

    Very nice! I’ve always done with this JS, never thought of doing it with PHP. Will definately use this in the future.

    • User Avatar
      Permalink to comment#

      Here’s a reply on a five-year-old post but hey, I believe I’m adding something useful…

      Just to point it out in case anyone’s thinking of using JS: with a JS method, it’s prone to abuse or great error, as you’d be relying on the end user’s PC to have the right time — unless you were using Ajax to pull the real time from the server.

    • User Avatar
      Permalink to comment#

      @Dave what kind of abuse would you imagine could happen to the copyright date on a website?

  2. User Avatar
    Permalink to comment#

    Wow! I’ve used the date feature of PHP, but had never thought to use it in that instance.

  3. User Avatar
    Permalink to comment#

    Nice, am now using the date function to store system date to database.

  4. User Avatar
    Permalink to comment#

    Very simple… Nice when copyrights include two years. But if only one (for example company was established just at present year) that code is unsuitable. More universal is…

    $start_year = 2007;
    if ($start_year == date("Y")) {
            echo $start_year;
    } else {
        echo $start_year."-".date("Y");
    • User Avatar
      Permalink to comment#

      That’s perfectly good code, it’ll just take the server that bit longer to process, I know people who won’t use the php date function in the copyright because of the extra load time and have a feeling this would send them into shock.

      Personally for ease of use I’d use the single copy date or even just the same year to same year i.e. 2007-2007 until the year changed.

    • User Avatar
      Permalink to comment#

      “I know people who won’t use the php date function in the copyright because of the extra load time”
      For actual real? Do they run their server on a pocket calculator? Asking for a friend..

  5. User Avatar
    Permalink to comment#

    Sorry, forgot to remove tags from previous post, please delete it.

    $starting_year = 1945;
    echo ($starting_year==date('Y')) ? date('Y') : $starting_year." - ".date('y');
  6. User Avatar

    // if both years are the same display only the current year ,
    // if they are different display both with an en dash between them
    $startYear = 2011;
    $thisYear = date(‘Y’);
    if ($startYear == $thisYear) {
    echo $startYear;
    } else {
    echo “{$startYear}–{$thisYear}”;

  7. User Avatar

    I’ve put the following in my html document:

    Copyright © company name All rights reserved

    but nothing happens!

    explanation appreciated

    why is my php text not displaying to try and explain what is going wrong???

    what charachters do i need to put before my text in order for this web page to display my text and not parse the code?

  8. User Avatar
    Permalink to comment#

    Great code. Thanks!

  9. User Avatar
    Permalink to comment#

    Peter, your page needs to be saved as a PHP i.e. somepage.php – Also, if your trying to view the php page on your local machine it won’t work, all you get is a blank page. To do this you will need to download & install either WAMP or XAMPP, then copy your php page over to WAMP/XAMPP (make sure they are turned on before trying to view the php page). Once copied, type in to your URL bar in your browser; localhost or http://localhost

  10. User Avatar
    Permalink to comment#


    I had to put the following in the htaccess file in the root directory for imbeded php in html files to work.

    RemoveHandler .html .htm
    AddType application/x-httpd-php .php .htm .html

  11. User Avatar
    Mike Wyatt II (@entelleckt)
    Permalink to comment#

    Thanks for the snippet Chris! Had a friend whose WordPress theme used to output the copyright year for him but a core function the theme depended on to output the year changed and created errors for him.

    Thanks to your snippet I was able to fix his flawed theme.

  12. User Avatar
    Dubai web design, development
    Permalink to comment#

    I’ve used the date feature of PHP, but had never thought to use it in that instance.

  13. User Avatar
    Permalink to comment#

    Thanks! Works perfectly!

  14. User Avatar
    Permalink to comment#

    This was great thanks, managed to fix up something that has been bothering me for a long time.

  15. User Avatar
    Permalink to comment#

    the scripts posted at the top of the page won’t work unless you place a semi-colon just prior to the closing php tag… like so

  16. User Avatar
    Al Bauguess
    Permalink to comment#

    $copyrightyear=($startyear==date(‘Y’)?$startyear:$startyear.” – “.date(‘Y’));
    echo $copyrightyear;

  17. User Avatar
    Al Bauguess
    Permalink to comment#

    Make the three 2000’s your start year

    echo $copyrightyear=(“2000″==date(“Y”)?”2000″:”2000 – “.date(“Y”));

  18. User Avatar
    Al Bauguess
    Permalink to comment#

    Even Shorter

    echo ("2000"==date("Y")?"2000":"2000 - ".date("Y"));
  19. User Avatar
    Al Bauguess
    Permalink to comment#

    Complete php Copyright code for starting year 2013

    echo "Copyright © ".("2013"==date("Y")?"2013":"2013 - ".date("Y"))." · YourName · YourWebSite · All rights reserved";


    Copyright © 2013 · YourName · YourWebSite · All rights reserved

    Starting Year 2000

    echo "Copyright © ".("2000"==date("Y")?"2000":"2000 - ".date("Y"))." · YourName · YourWebSite · All rights reserved";


    Copyright © 2000 – 2013 · YourName · YourWebSite · All rights reserved

    • User Avatar
      Al Bauguess
      Permalink to comment#

      I Used HTML special characters for “©” and “·”(middle dot) did not show here.

  20. User Avatar
    Permalink to comment#


    Actually this part of the code intval($year) == ‘auto’ is a really bad practice. What you’re doing here is comparing an integer (due to the intval cast) with a string. It works only due to the fact, that you’re using the equal operator, and the string on the right side of equation gets automatically casted to the Integer.

    This might be really confusing to the programming beginners and should rather be avoided.

    Read more at:

    Last but not least, the code shouldn’t be covered with tags in every line of the function, they should be removed to increase the readability ;)

    Kind regards,


  21. User Avatar
    Permalink to comment#

    I have done some modification to use it with WordPress and I enhanced it a little bit.

    1.) Paste this to your theme functions.php file:

    function auto_copyright($year = 'auto', $name){ 
        $copy = ' &copy; ';
        if(intval($year) == 'auto'){ 
            $year = date('Y').$copy.$name; 
        if(intval($year) == date('Y')){ 
            echo intval($year).$copy.$name; 
        if(intval($year) < date('Y')){ 
            echo intval($year) . ' - ' . date('Y').$copy.$name; 
        if(intval($year) > date('Y')){ 
            echo date('Y').$copy.$name; 

    2.) And use this anywhere you want to display copyright:

    <?php  auto_copyright('2014','ADD SOME COPYRIGHT TEXT'); ?>

    And the output of this all is:


    Depending on the year, function can look also like this

    2008 – 2014© ADD SOME COPYRIGHT TEXT

    And that is all.

  22. User Avatar
    Karen Law
    Permalink to comment#

    Hi there!

    Thanks so much for this helpful post. I tried using your code for my headway themed wordpress site that I am starting but I could not get it to work :(
    I am trying to put a Copyright at the footer of my website so that year updates to the current year automatically. I tried using this in the visual editor of headway:

    Copyright @ Premiere Condos, Karen Law

    But it does not work… you know what I am doing incorrectly?

    Thank you so much for your time!

    • User Avatar
      Permalink to comment#

      #Karen Law..its this simple. the foooter.php file. Find the line which references the footer message and within that line create php tags and you are done. Look here:
      Copyright © .

      This will definitely do you a great deal.

  23. User Avatar


    The function works well but just one question… why does each line contain opening and closing PHP tags? Why not just put the tags around the whole lot? It would be more efficient this way.


  24. User Avatar

    hanks for the info! I know you can’t nest PHP functions within eachother… how would I get this to work for something like this? (I want to next this date php inside the printf php I already have)

    "?php printf( __( '© YEARPHP | NAME')); ?"
  25. User Avatar
    Permalink to comment#

    Richard, i feel the author just put the tag in there to let the user know the tags have to be present to allow the function kick in (for .php)

    Also there’s an easier way or what i consider easy, i have actually applied this in many instances whilst parsing output via php.

    $copydate = date(“Y”);

    //Everything else can go in here :)

    //Declare or call it up anywhere you need it
    $message .= “Written by ExitNode © “.$copydate.”\n”;

    Written by ExitNode © 2014 ($copydate gives the current year)

  26. User Avatar
    Permalink to comment#

    Copyright notices are not necessary to be protected by copyright law. This is universally true across all western nations.

    Having an automatically updating copyright year is absolutely stupid. It means that for content you wrote in 2011, you’re telling the world that you wrote it in 2014 (or whatever year it currently is). This can create problems for you if there is ever a dispute and the only proof you have that you are the original copyright owner is the copyright notice on your website. Your copyright notice should reflect the year in which the content was created.

    These copyright notices are something that everyone really needs to stop doing, especially when it comes to adding a misleading or downright incorrect year. You should only be putting it in there if there is an actual need to do so. It does absolutely nothing to help you from a legal standpoint and it can only potentially hurt you if the information you provide is incorrect.

  27. User Avatar
    Permalink to comment#

    Better yet:

  28. User Avatar
    Permalink to comment#

    This for lazy ppl xD

  29. User Avatar
    Permalink to comment#

    hi use this code

    Copyright © All rights reserved pbimt.

  30. User Avatar
    Permalink to comment#


  31. User Avatar
    Permalink to comment#

    Thanks, very cool!

    Shared from my pages.

  32. User Avatar
    Permalink to comment#

    copyrights © where i paaste this code in footer.php

  33. User Avatar

    All those php starts and stops are cute. It’s good practice to include all your PHP between one set of PHP open and close tags. Even if you just echo all the HTML in php, it would prevent the server from having to open and close php more than once on the page.

  34. User Avatar

    date_default_timezone_set(); is required now, example;

    i have a php config file with:

    function auto_copyright($year = 'auto'){
            date_default_timezone_set('Europe/London'); // REQUIRED ! Set timezone
            if(intval($year) == 'auto'){ $year = date('Y'); } 
                if(intval($year) == date('Y')){ echo intval($year); } 
                if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } 
                if(intval($year) > date('Y')){ echo date('Y'); } 

    then this where i output it in my footer:

    © <?php auto_copyright('2008');  // 2010 - 2011 ?> Your Company.All rights reserved.
  35. User Avatar
    Permalink to comment#

    Just a note that the snippet titled “Start date with error protection” will not work with it’s default auto value. intval('auto') will always evaluate to 0 and so will never be equal to the string auto.

    Aside from that obvious bug, it’s also quite a nasty looking piece of code with a fair bit of fluff. Here’s my functionally equivalent cleaned up version:

    function auto_copyright( $year = null ) {
        $currentYear = (int) date( 'Y' );
        if ( $year === null || $year >= $currentYear ) {
            $result = $currentYear;
        } else {
            $result = "$year - $currentYear";
        echo $result;
    • User Avatar
      Permalink to comment#

      Perhaps I spoke too soon about the default auto value bug. However, it only works because it’s doing a loose comparison between the integer 0 and the string ‘auto’, which PHP evaluates to true.

      Still, my version removes all the fluff and some unnecessary logic :)

  36. User Avatar
    Permalink to comment#

    You can use PHP short tags for cleaner code:

    © 2011–<?= date('Y') ?>

    And there’s no need to use a character escape for the copyright symbol (unless your site uses a legacy character encoding, other than UTF-8).

  37. User Avatar
    Permalink to comment#

    This also works when using PHP shorthand:

    <?= date("Y"); ?>

    Rock on!

  38. User Avatar
    Dave Hall
    Permalink to comment#

    My feeling is that a date span should use an n-dash (&ndash;) not a hyphen (-). It’s visually and semantically more agreeable (a hyphen being the same glyph as a minus sign). Most style guides would agree, but then it depends on how spans are dealt with across your site. It’s more important to be consistent than to be correct.

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.