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(
      'return $i[1].esc_html($i[2]).$i[3];'


Useful links

Guest Post

This post is written by Sergej Müller, 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!

List Posts by Category In Navigation

WordPress is primarily a blog platform. Not infrequently it is used as a CMS. But not just static pages play a role, but also posts, because they are giving more opportunities, having better performance and be published in feeds. Therefore, I prefer to use, in the context of WP as a CMS, posts more than the static pages. From time to time are the wishes of a navigation layout very extra odinary. And so was it in my recent project, the requirement to list the posts from each category in the navigation.
This is unusual as in the long run, you will have many posts, and the navigation will be very confusing - still, in this project it made sense, since we won't have many posts.

The small function lists the category and below the posts. There is a parameter that restricts the output of the posts, so that in extreme cases, not too many will be listed, only the last posts - $mylimit. The value -1 for this parameter provides all posts. The function itself belongs to the functions.php of the theme or in a Plugin. An exemplary use can be found below the function.
Continue reading …