Skip to content
  • Home
  • Shortcodes
  • Plugins
  • IT / Windows
  • Programming & Development
  • Random

2

Escape WordPress shortcodes in content with a shortcode

Maybe not how you were expecting to solve this problem, was it? Maybe you thought about it and here I have one for you. I just wrote an article about integrating Google +1 and noticed that anywhere the shortcode [p1] is placed is executed. Not what we want when we are showing someone how to use them.

This is the escape shortcode:

[esc][p1][/esc]

This is how the shortcode appears after it has been escaped.

[p1]

The Escape Shortcode

There will be a time when you want to write about a cool shortcode you created like I just did and you will need your shortcodes to be un-executed.

// HTML Special Chars shortcode
function escapeHTML( $atts, $content=null ){
	/* Author: Nicholas P. Iler
	 * URL: http://www.ilertech.com/2011/06/escape-wordpress-shortcodes-in-content-with-a-shortcode/
	 */
		$plus1_code = htmlentities($content);
		return $plus1_code;
}
add_shortcode('esc', 'escapeHTML');

Conclusion

Now, you can escape anything you like. Not just shortcodes. I found a resource that suggest that merely entering double-brackets escapes them like this “[[ ]]” but I have not found this to work for me so I just threw this one together already knowing about the core PHP function htmlentities.

Related Posts

  • Add Facebook Like Button to WordPress 3.0 with a simple shortcode
  • Add Google + 1 to WordPress 3.0 with a simple shortcode
  • Add Twitter Follow Button to WordPress 3.0 with a simple shortcode
  • Add Twitter Share Button to WordPress 3.0 with a simple shortcode
  • What’s wrong with the WordPress Redirection Plugin?

About Nickiler

Web Developer and Systems Admin
View all posts by Nickiler →

Follow @Nickiler
Posted on June 6, 2011 by Nickiler
This entry was posted in Shortcodes and tagged escape, wp. Bookmark the permalink.

2 Responses to Escape WordPress shortcodes in content with a shortcode

  1. Preston says:
    February 4, 2013 at 2:27 PM

    hey there and thank you for your information
    – I have certainly picked up anything new from right here.

    I did however expertise some technical points using this
    website, as I experienced to reload the site many times previous to I could get
    it to load properly. I had been wondering if your
    web hosting is OK? Not that I’m complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your high-quality score if ads and marketing with Adwords. Well I’m adding this RSS to my email and could look out for a lot more of your respective interesting content.
    Ensure that you update this again very soon.

    My web blog; Preston

    Reply
  2. Dean Oakley says:
    March 11, 2013 at 2:42 PM

    I don’t think double brackets is working anymore. This does so thanks!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Recent Posts

    • WP Vanilla Connect
    • Add Twitter Follow Button to WordPress 3.0 with a simple shortcode
    • Add Twitter Share Button to WordPress 3.0 with a simple shortcode
    • Add Facebook Like Button to WordPress 3.0 with a simple shortcode
    • Escape WordPress shortcodes in content with a shortcode
  • Recent Comments

    • Dimo on [Updated] These files can’t be opened. Your Internet security settings prevented one or more files from being opened – Solved
    • casino on Creating a USB bootable disk with a Custom Windows PE image using AIK
    • orthodontists in Middletown on Creating a USB bootable disk with a Custom Windows PE image using AIK
    • Kasey on Creating a USB bootable disk with a Custom Windows PE image using AIK
    • Nickiler on WP Vanilla Connect
  • Categories

    • IT / Windows
    • Plugins
    • Programming & Development
    • Random
    • Shortcodes
    • WordPress
  • Archives

    • January 2012
    • July 2011
    • June 2011
    • September 2010
    • August 2010
    • June 2010
    • May 2010
    • November 2009
ilertech
Proudly powered by WordPress.