-
Hey guys, I use the shortcode [year] in my title to display the current year. However when I added the plugin Contextual Related Posts – https://wordpress.org/plugins/contextual-related-posts/ my shortcodes are not working on the related posts grid.
Provided the examples in the private section.
-
Hi there,
Do you mean you add
[year]
to the h1 headline?Can you show me the PHP code that was used to create the
[year]
shortcode?Does the shortcode work in the content area via a shortcode block?
Let me know 🙂
-
Hey Ying,
THe shortcode is throughout the whole site. So if I mention the term [year] it will display the current year in the main content, Page title, Category Pages, etc.
I had the problem before where it wouldn’t appear in the category pages when posts were displayed but they fixed within that code.
PHP code for the shortcode is here: (also left in the private information)
Here’s the shortcode I currently have in the code snippets. PHP
function modify_post_title_shortcode( $title ) {
// Execute the shortcode and replace it with its output
$title = do_shortcode( $title );// Return the modified title
return $title;
}
add_filter( ‘the_title’, ‘modify_post_title_shortcode’ );Let me know if you need anything else!
-
Hi there,
you would need to speak to the Contextual Related Posts developers.
And ask if its possible for their plugin to render a shortcode in the title. -
Thanks David, I went through their support forum there (didn’t even know they had one) and saw this thread here https://wordpress.org/support/topic/shortcode-not-working-with-plugin/
Very simple step just adding the code
add_filter( ‘crp_title’, ‘do_shortcode’ );
Appreciate your support man!
-
Glad to hear you found the answer, and thanks for sharing that.
- You must be logged in to reply to this topic.