• Resolved stevehoo

    (@stevehoo)


    I have some [permalink] shortcodes as well as [wpf-filters id=1] in my category descriptions. They’re nothing special to the meaning, just links to other pages in my site and product filters. But, they’re showing up in the auto generated snippet.

    I’d like to remove them.

    • This topic was modified 9 months, 2 weeks ago by Yui.
    • This topic was modified 9 months, 2 weeks ago by stevehoo.
    • This topic was modified 9 months, 2 weeks ago by stevehoo.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Rank Math

    (@rankmath)

    Hello @stevehoo,

    Thank you for contacting the support.

    You can use this filter to process the Shortcodes on the frontend:
    https://rankmath.com/kb/filters-hooks-api-developer/#allow-shortcodes

    But the SERP preview in the backend will still show the Shortcode codes because WordPress doesn’t have any function to process the Shortcodes in JavaScript.

    Hope that helps.

    Thread Starter stevehoo

    (@stevehoo)

    Thank you for the better explanation. As, I searched and found this filter, added it, but saw no change on the backend and decided it wasn’t working, or not what I needed. I neglected to check on the front.

    I hope that my question, your answer and this will aid others who look for the same problem and solution.

    Thread Starter stevehoo

    (@stevehoo)

    My bad, having actually checked to see if it works… It does not.

    See https://i.imgur.com/EzlkjTs.jpg

    I’ve added to my functions.php
    add_filter( ‘rank_math/paper/auto_generated_description/apply_shortcode’, ‘__return_true’ );

    But still seeing shortcodes in my descriptions.

    • This reply was modified 9 months, 2 weeks ago by stevehoo.
    Thread Starter stevehoo

    (@stevehoo)

    This has worked for me:

    add_filter( 'rank_math/frontend/description', function( $description ) {
    	return strip_shortcodes($description);
    });
    Thread Starter stevehoo

    (@stevehoo)

    And… This is much better, as it strips the shortcode, but leaves the content inbetween.

    add_filter( 'rank_math/frontend/description', function( $description ) {
    $description = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $description);
        return $description;
    });
    Thread Starter stevehoo

    (@stevehoo)

    And, in the furtherance of science, as I didn’t find it elsewhere. The yourls shortner, shortlink

    add_filter( 'rank_math/opengraph/url', function( $url ) {
        global $post;
        $og_url = get_post_meta($post->ID, '_yourls_url', true ); // Change post_meta_key with your the meta key from your site.
        if ( ! $og_url ) {
            return $url;
        }
        return $og_url;
    });
    Plugin Author Rank Math

    (@rankmath)

    Hello @stevehoo

    Thank you for sharing all these snippets with us.

    We have forwarded them to our content team and requested them to add these to our website.

    If there’s anything else we can help you with, please let us know. We are here to assist.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide or process shortcodes in snippets’ is closed to new replies.