Support » Theme: OceanWP » Shortcodes in breadcrumbs from post title not working

  • Hi, I have an issue with breadcrumbs output by the theme and shortcodes in post titles.

    I use this code to display a shortcode in the title:

    
    // Activate shortcode function in Post Title
    add_filter( 'the_title', 'do_shortcode' );
    
    // Shortcode to display the current year in WordPress
    // shortcode: [year]
    add_shortcode( 'year' , 'current_year' );
        function current_year() {
        $year = date("Y");
        return "$year";
    }
    

    The theme does not interpret the shortcode when generating the breadcrumbs, and just outputs [year] into the breadcrumb anchor text.

    Is there any way to fix this?

    Thanks,
    Tom

Viewing 5 replies - 1 through 5 (of 5 total)
  • I just tested your code and it works great in the post title and breadcrumb. Can you tell me where you are adding the shortcode? Please link to the page where you have the issue.

    • This reply was modified 2 years, 5 months ago by Amit Singh.
    Thread Starter theguitarlesson

    (@theguitarlesson)

    Sure, here it is. Check the breadcrumb, it says [year].

    Also just noticed that the Twitter share text has [year] as well, not the result of the shortcode.

    Thanks,
    Tom

    Try to add the below code to the functions.php file of the child theme to fix it –

    add_filter( 'breadcrumb_trail', 'do_shortcode' );

    Thread Starter theguitarlesson

    (@theguitarlesson)

    Thanks, that fixed the shortcode.

    But the Twitter share text still has [year] in it. If you go to the example page linked above and click the Twitter share link you’ll see it.

    Is there a filter for sharing texts as well?

    Thanks,
    Tom

    I don’t think it is possible for the social share plugin. There is no filter for it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shortcodes in breadcrumbs from post title not working’ is closed to new replies.