• Hi,

    I’m using a shortcode on a post template to insert a block of text onto every page of my site (using the Resuable Blocks Extended plugin to generate the shortcode).

    I’d like to exclude the shortcode and text from some pages though. Is it possible to do this on individual pages?

    Many thanks,

    Adam

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello @adam555,

    Yes, it is possible to exclude a shortcode on individual pages.

    Thread Starter adam555

    (@adam555)

    Hi Aminul,

    Thanks for your reply. Can you tell me how?

    Many thanks,
    Adam

    Hello @adam555,

    You can check this plugin. I think it will help you. If you don’t understand i will share with you how to excluded shortcode by coding.

    https://ww.wp.xz.cn/plugins/shortcodes-ultimate/

    Thread Starter adam555

    (@adam555)

    Hey Aminul,

    That’s great, thanks, I’ll take a look. Could you share with me the coding method as well?

    Many thanks,
    Adam

    Hello @adam555,

    You can try this method to exclude.

    function shortcode_function($atts, $content = null) {
        // Check if the current page is excluded
        if (is_page('page-slug)) {
            return ''; // Return an empty string to exclude the shortcode
        }
    
        // Process the shortcode and return content
        return '<div class="shortcode-content">' . $content . '</div>';
    }
    add_shortcode('shortcode', 'shortcode_function');

    Thread Starter adam555

    (@adam555)

    Hi Aminul,

    Many thanks for this, much appreciated. Could you explain a bit more about how to implement this an exclude specific pages? I’m not coder but have some basic experience.

    Many thanks,
    Adam

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Excluding a shortcode element from individual pages’ is closed to new replies.