Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

[year] Shortcode Not Working With Related Posts

  • 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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.