Bricks Dynamic Tag: {wpide_year}
Adds a {wpide_year} dynamic data tag to Bricks that outputs the current year, for footer copyright lines that update themselves.
Opens WPIDE on
Code
add_filter( 'bricks/dynamic_tags_list', function ( $tags ) {
$tags[] = array( 'name' => '{wpide_year}', 'label' => 'Current year', 'group' => 'Site' );
return $tags;
} );
add_filter( 'bricks/dynamic_data/render_tag', function ( $tag, $post = null, $context = 'text' ) {
$name = is_string( $tag ) ? trim( $tag, '{}' ) : $tag;
return 'wpide_year' === $name ? wp_date( 'Y' ) : $tag;
}, 20, 3 );
$wpide_bricks_year_replace = function ( $content ) {
if ( ! is_string( $content ) || false === strpos( $content, '{wpide_year}' ) ) {
return $content;
}
return str_replace( '{wpide_year}', wp_date( 'Y' ), $content );
};
add_filter( 'bricks/dynamic_data/render_content', $wpide_bricks_year_replace, 20 );
add_filter( 'bricks/frontend/render_data', $wpide_bricks_year_replace, 20 );
Notes
Find it in the dynamic data list under "Site". You can also type {wpide_year} into any text field.
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.