Support » Developing with WordPress » Display Shortcode in pre without execution

  • Shaped Pixels

    (@shaped-pixels)


    Does anyone have a sure-fire way to stop WordPress from executing shortcode in pre tags from within the editor and the site’s front-end?

    Adding an extra [ in front of the shortcode and ] at the closing shortcode does not work. I also tried a function I got off a WordPress.stackexchange, but that didn’t work either. I have a lot of shortcodes to display for my users, but they are being executed.

    IMPORTANT NOTE: I am using my own theme for my own site, as well, my own shortcode plugin for the shortcodes I am using for the site, but I need to display the actual shortcode (code) in tutorials.

    I miss my Joomla site 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • gnoric

    (@gnoric)

    Have you tried tripple opening and tripple closing? Else you could try using the ascii codes [ and ]

    Shaped Pixels

    (@shaped-pixels)

    I tried so many things…nothing worked for me, so what I did was used html code from the front of the site, replaced my shortcode with that, for the areas I am using it in my own site, then disabled the plugin. Now all my theme tutorials that needed to just show the shortcode (code), is working in the pre tags.

    Moderator bcworkz

    (@bcworkz)

    gnoric’s suggestion of HTML entities is probably the most practical, but sort of annoying to need to remember to do this.

    If you want an automatic, idiot proof solution, assuming the post content also has shortcodes that do need to be processed, then you need to replace the default shortcode callback to “the_content” filter with a custom version. This version would break up the content into segments split at the pre tags. Then apply do_shortcode() to the non-pre segments before reassembling the segments back together.

    You can explode() the content on pre> and not process shortcodes for segments that end with </. Then implode() using the same string as “glue”.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Shortcode in pre without execution’ is closed to new replies.