I have lots of posts where I have current month with the post title.

When month ends, it's kind of annoying to change all the posts manually. So, I created a shortcode to show the current month.

I used add_filter( 'the_title', 'do_shortcode' ); to execute the shortcode in title. It all works fine.

Problem is, in the meta title, the raw shortcode is showing instead of the output.

Any suggestions how I can work it out.

Thanks in advance.


The filter for the title is single_post_title, you can do the same thing you do with the_title:

add_filter( 'single_post_title', 'do_shortcode' );
  • Hi Milo, Thank you very much. That works. I just found out that I didn't have to use shortcode. I could use Yoast SEO. They have variables like %%currentmonth%%, %%currentyear%% which automatically shows the month and year. That's more convenient. Thanks anyways. – Imtiaz Rayhan May 9 '17 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.