Wordpress Tip: Stop Wordpress from stripping markup in your posts

March 8th, 2008 - Posted in Wordpress Tips |

Wordpress have a nasty habit of stripping html markup from posts. Most bloggers won’t really notice this because they are not posting html tags. I ran into this problem after I activated the wp-syntax plugin for code highlighting and formatting. When you want to highlight code with wp-syntax, you have to add <pre lang=’php’ line=’1′> to your posts using the code tab, not the visual tab in your blog post editor.

Wordress will only accept <pre> with no attributes. If you add them, Wordpress will strip them. The way around this, an any other code problem is to edit the kses.php file located in the wp-include folder. Once in that file, look for this:

$allowedposttags = array(
 
     'address' => array(),
 
     'a' => array(
 
          'href' =>; array(),
 
          'title' => array(),
 
          'rel' => array(),
 
          'rev' => array(),
 
          'name' => array()
 
),

It actually goes on and on, but I am only showing the top 2 tags. As you can see when you add an tag to a post (link to another website) you can only add the 5 attributes href, rel, name, title, and rev. If you add something like “style = ‘#cc0000;’” it will be stripped.

Here is the section I needed to update to get wp-syntax to work:

'pre' => array(
 
      'width' => array(),
 
      'lang' => array(),
 
      'line' => array()
 
),

Default only allows a pre tag to include width. I added lang, and line. Also, you must add => array() to each line. It is pretty self explanatory.

Also, a thanks goes out to Gergely Hodicska for the post, and fix, for escaping characters. Works like a charm.


1 Response to “Wordpress Tip: Stop Wordpress from stripping markup in your posts”

  1. 1 WP-Syntax - WordPress Plugin - zxblog.laullon.com

Leave a Reply


Add to Technorati Favorites

Featured Sections