"Privacy Policy Last Updated" Date Shortcode
Adds a [privacy_policy_updated] shortcode that prints the date your privacy policy page was last changed, so the date on the page is always correct.
Opens WPIDE on
Code
add_shortcode( 'privacy_policy_updated', function ( $atts ) {
$atts = shortcode_atts( array(
'format' => get_option( 'date_format' ),
'prefix' => 'Last updated: ',
), $atts, 'privacy_policy_updated' );
$page_id = (int) get_option( 'wp_page_for_privacy_policy' );
if ( ! $page_id || 'publish' !== get_post_status( $page_id ) ) {
return '';
}
return '<p class="wpide-policy-updated">' . esc_html( $atts['prefix'] . get_the_modified_date( $atts['format'], $page_id ) ) . '</p>';
} );
Notes
Use [privacy_policy_updated format="F j, Y"] to choose a date format; it defaults to your site's date format.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.