How do you add in dynamic month and year in code snippets?
-
I’m trying to add in the dynamic month and year in my blog post titles, but it isn’t working.
This is the code I entered into Code Snippets. I’m using Rank Math as my SEO plugin. Is the code correct?
//* Shortcode to display the current month and year in WordPress //* shortcode: [month_year] add_shortcode( 'month_year' , 'current_month_year' ); function current_month_year() { $year = date("Y"); $month = date("M"); return "$month, $year"; } add_filter( ‘the_title’, ‘do_shortcode’ ); // activate shortcode in WP Title add_filter( ‘rank_math/frontend/title’, ‘do_shortcode’ ); // activate shortcode in Rank Math Title add_filter( ‘rank_math/frontend/description’, ‘do_shortcode’ ); //activate shortcode in Rank Math Meta Description
For my blog post title, I put “The Best XXX in [month_year]”, but the month and year doesn’t show up.
Currently I’ve removed the [month_year] from the blog post title since it’s not working.
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How do you add in dynamic month and year in code snippets?’ is closed to new replies.