O
O
Oleg Roslyakov2021-10-26 00:09:53
WordPress
Oleg Roslyakov, 2021-10-26 00:09:53

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

2 answer(s)
A
Artem Zolin, 2021-10-26
@artzolin

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 );
}

To replace data in the database, you can get the desired records with get_posts()and update in a loop withwp_update_post()

O
Oleg Roslyakov, 2021-12-06
@Lawyer-u

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 question

Ask a Question

731 491 924 answers to any question