Use WordPress Shortcodes outside the Editor

The Shortcode-API can help to make your Editor more advance especially with the help of Shortcodes to insert external content to your posts or pages easily. There are many possibilities, as you can see in this example Easy Way For Advertisement.

But if sometimes you like to use a Shortcode in your Template or just don't like to put it in the Editor, for example you like to insert it in the Custom Field or somewhere else. There is a function in WordPress which helps you to insert a shortcode somewhere else besides your Editor.
Continue reading …

Convert Content of Pre-Tags in HTML-Code

There are two different ways to display a source code instead of executing a source code in a post or page. Depending on preferences which HTML tag is defined in the style sheet and provided with formatting, code fragments are either declared by <code> or <pre>. In some cases, combining the blogger even both tags.

Conversion of special characters

If you want to use the pre Tag, then you have to take care that the code snippets, while parsing, are not executable. HTML-Entity is the solution.

Two options are available: One, manually, such as search and replace before pasting into the editor (HTML-Entities-table). but if you are smart you let WordPress doing the job.

Numerous methods for the simple conversion of the code set between pre-and/or code tags are on the web. But there is one for the direct use in WordPress, which takes over to convert the characters perfectly since WordPress 2.8.

//PHP-Code for functions.php

function pre_esc_html($content) {
  return preg_replace_callback(
    '#(<pre.*?>)(.*?)(</pre>)#imsu',
    create_function(
      '$i',
      'return $i[1].esc_html($i[2]).$i[3];'
    ),
    $content
  );
}

add_filter(
  'the_content',
  'pre_esc_html'
);

Useful links

Guest Post

This post is written by Sergej Müller wpseo.org, who created the popular WordPress Plugin to optimize your SEO.

Thank you very much from our part to Sergej.

If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!