Textpattern tips, tutorials and code snippets

Copyright dates

This tip has been archived. Please see the newer version of this tip.

Strictly speaking, every time a text is amended, the particular year should appear in the copyright notice i.e © 2010, 2012 for which case there is the plugin sed_copyright (now sadly orphaned).

The following code features another method without using a plugin.

Use PHP to output the year

<txp:variable name="year" value='<txp:php>echo safe_strftime("%Y");</txp:php>' />
<txp:if_variable name="year" value='<txp:posted format="%Y" />'>
    &copy; <txp:variable name="year" />
<txp:else />
    &copy; <txp:posted format="%Y" />–<txp:variable name="year" /> 
</txp:if_variable>

The code detects if the article was posted this year and would therefore display &copy; 2014.

If it was posted any year before the current year of 2014, then it will display that year and the current one – i.e &copy; 2009–2014.

Here is the code in action

© 2014–2024