Raw HTML Plugin for WordPress

Introduction

Recently I needed to put some style definitions and a JavaScript function in a post on another blog that I have. I wasted several hours trying to do this, because WordPress insisted on putting backslashes in front of my apostrophes, inserting superfluous <p> or <br /> tags in place of newlines, and generally breaking my HTML in various horrible ways.

In the end I decided to just go and write a plugin that would let me disable the automatic formatting that WordPress applies to post content. This plugin adds a set of shortcodes that you can use to “protect” specific parts of your post and prevent WP from messing with them.

Download & Installation

Requirements :

  • WordPress 2.8 or later
  • If you use the free version, I strongly recommend disabling the visual editor. It (the editor) can mess up your code even if you use this plugin.

Installation is straightforward – download the zip file, unzip, upload the raw-html folder to /wp-content/plugins and activate it in the Plugins tab.

Usage

There are two ways to use the plugin. First, to turn off “smart quotes” and other built-in filters for an entire post, use the checkboxes that Raw HTML adds to the “Edit Post” screen:

Raw HTML meta box screenshot

If you want to prevent a specific part of your post or page from being processed and “texturized” by WordPress, wrap it in ... or <!–raw–>…<!–/raw–> tags. The two versions work exactly the same, with one exception – the <!–raw–>’s won’t be visible to your visitors even if you deactivate the plugin.

Example :
<!--raw-->
This

is

a ‘test’!
<!–/raw–>

Result :
This is a 'test'!

If you view the source code of this page, you will see that the newlines are still there, and the apostrophes haven’t been converted/escaped.

Other Notes

This plugin is provided AS IS, with no guarantee that it will work on your site.

Related posts :

318 Responses to “Raw HTML Plugin for WordPress”

  1. […] balise <code> (mais dans ce cas, j’utilise le short­code [raw], per­mit par l’extension Raw HTML) ou bien dans un texte dans une autre langue (lang="en"» ou xml:lang="en" , par […]

  2. […] plus ana­ly­ser qu’un texte se trouve dans une balise <code> (j’aurais bien uti­lisé Raw HTML et sa balise <!–raw–>, mais il y a une incom­pa­ti­bi­lité) ou bien dans un texte […]

  3. […] Having realized that WordPress does not allow us to type JavaScript in our posts, I tried to find out how to add Web Ring navigation URL into a post. After some googling and trial and error, finally got this nice plugin called RAW HTML. […]

  4. […] Having realized that WordPress does not allow us to type JavaScript in our posts (or pages), I tried to find out how to add Web Ring navigation URL into a post. After some googling and trial and error, finally got this nice plugin called RAW HTML. […]

  5. […] Versão 1.4.8 | Por Janis Elsts | Visitar o site do plugin […]

  6. thomas says:

    hi there,

    when activating raw html, all other plugins that parse the post-text in some kind of way aren’t executed any more.

    when deactivating add_filter(‘the_content’, ‘wsh_extract_exclusions’, 2); all works fine – more or less 😉
    breaks are keeped, only thing is, that edit text was:
    -raw-
    bla
    bla

    bla
    -/raw-

    is in html now:
    -raw–/raw-
    bla
    bla

    bla

    the rest is as it should be.

    have a hint why?

    regards,
    thomas

  7. Jānis Elsts says:

    When you say other plugins aren’t executed any more, do you mean that they no longer work on the text in [raw]…[/raw] tags, or that they stop working completely, even in posts that don’t use the [raw]” tags?

    If it’s the former, then that’s the intended result – Raw HTML protects text within [raw] tags from being modified by WordPress and most other plugins. This is why shortcodes and other dynamically generated code won’t work inside [raw] tags.

    On the other hand, if other plugins stop working completely, that sounds like a plugin conflict. Could you tell me what plugins you’re using so that I can install them and test them for compatibility issues?

  8. I’m wondering if you would have an idea why the opening div on my “About” page seems to get messed up: http://greggkellogg.net/home/about/.

    I’m runnng WP 3.9.1 and 1.4.12 of the Raw HTML plugin.

    If I try removing the div, or putting something in front of it, the problem just moves somewhere else.

    It’s great to be able to use raw HTML, for things such as custom RDFa/Microdata markup.

  9. Jānis Elsts says:

    I don’t know what could cause that. How does that part of the page look in the post editor? Which parts of the code are using [raw] tags, and are all the tags properly matched (no orphan/unclosed tags)?

  10. Massimiliano says:

    is possible enable othre plugin tag ?

  11. Tup says:

    I have problem with WP 3.9.1 and when visual editor is disabled. Everything inside [raw] will get escaped thus totally messing up the HTML code. This doesn’t seem to work properly any more in recent WordPress versions. I have to disable the visual editor because now everything inside [raw] will either get mangled by it or just disappears completely.

  12. Tup says:

    It will end up looking like this after saving the post:
    [raw]<table class="table" style="width: 100%;">
    <tr>

    and so on… Enablinf/disabling Disable convert_chars doesn’t make any difference.

  13. Jānis Elsts says:

    Wait, so are you entering the code in Text or Visual mode? Or entering it in Text and then switching to Visual? As the documentation says, the [raw] tags will only work in Text/HTML mode. Switching to Visual is very likely to mess up the code.

  14. […] Raw HTML capability修正wordpress的自動修正語法不當的狀況(例如美式的引號會被轉成其他符號)。 […]

  15. Paul Cutmore says:

    I like the RAW plugin and use it with OSMaps, see for example
    http://cambridgeramblers.org/walk-programme-map/

    A while back I had developed a webpage showing a route (polyline) on the OSMap and this used to work fine. I have not looked at it for many months, but now the route no longer displays, even though the map and markers still display.

    The following link shows how it should look – but if I embed it in WordPress, between [raw] and [/raw], the blue route does not appear.
    http://cambridgeramblers.org/Test/FRW.html

    Any suggestions?

  16. Jānis Elsts says:

    When I open the first page you linked, there’s this error in the JavaScript console:

    Error: TypeError: linesLayer is undefined
    Source File: http://cambridgeramblers.org/walk-programme-map/
    Line: 254

    Looking at the page source code, it looks like the code that sets up the line is commented out:

    // Set up layer for the route
    // linesLayer = osMap.getVectorLayer();

    Have you tried uncommenting it?

  17. Michael says:

    when I wrap a post’s content in [raw], it won’t show up when calling the_excerpt() any way around that?

  18. Jānis Elsts says:

    Yes, add this line to your wp-config.php file:


    define('RAW_HTML_KEEP_RAW_IN_EXCERPTS', true);

Leave a Reply