• Resolved RyanPrentiss

    (@ryanprentiss)


    How do I go about preventing specific shortcode from displaying within a post via theme template? Specifically the gallery shortcode.

    I do not want to remove the shortcode from the post edit.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter RyanPrentiss

    (@ryanprentiss)

    Thanks for responding esmi, but question… is this a frontend function? I don’t want to remove the shortcode from the theme, only a specific post layout. Basically I want to be able to add the shortcode to a post within the edit screen, but stop it from being displayed on the published pages.

    Sounds foolish, but its a little bit easier for the novice WP user to upload images to a post as a full gallery, vs creating the gallery then deleting the shortcode or creating the gallery via the media page.

    Thread Starter RyanPrentiss

    (@ryanprentiss)

    strip_shortcodes( $content ) comes close, but that strips ALL shortcode.

    only a specific post layout

    What do you mean by specific? A specific post id? All single posts?

    Thread Starter RyanPrentiss

    (@ryanprentiss)

    I’m attempting to do it by post format.

    So, assuming you’re using a format-xxx.php file, add something like:

    <?php remove_shortcode('gallery');?>

    to the top of that template file.

    Thread Starter RyanPrentiss

    (@ryanprentiss)

    Thanks esmi, it works… but one last thing, it leaves the “[gallery]” on the page. Any suggestion on how to go about removing it??

    Thread Starter RyanPrentiss

    (@ryanprentiss)

    Nevermind, got it…

    functions.php

    function stripGalleryShortcode($content){
    	return preg_replace('/\[gallery\]/', '', $content);
    }

    custom template

    remove_shortcode('gallery');
    add_filter('the_content', 'stripGalleryShortcode', 10);

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Stop shortcode from displaying.’ is closed to new replies.