Answer the question
In order to leave comments, you need to log in
How to bulk change the year in H1 for a WP site?
Greetings! Tell me, how can I massively change the year in H1 for a site on WP to the current one?
Answer the question
In order to leave comments, you need to log in
The easiest way is to replace the regular expression when outputting to the front
add_filter( 'the_title', 'f711_title_filter' );
function f711_title_filter( $title ) {
return str_replace( '2020', '2021', $title );
}
get_posts()
and update in a loop withwp_update_post()
And if in H2 and H3 you also need to change the year, for example, there are 2019, 2020, 2021, immediately to the [year] shorcode. To no longer return to this issue, then how best to do? Do I need to write something in the functions.php file? The withdrawal function is on the site.
/*shortcode in article title */
function add_shortcode_to_title( $title ){
return do_shortcode($title);
}
add_filter( 'the_title', 'add_shortcode_to_title' );
in article body:
/* current year shortcode */
function year_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'year_shortcode');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question