Raw HTML Snippets WordPress Plugin

Ever since my über vent over fake shortcodes that autoformat the output of real shortcodes, I realized that the intention was good but the execution was bad.

So, I wrote a quick plugin that I thought was a more elegant (and that did not affect expected, core WordPress behaviors).

Raw HTML Snippets

This plugin allows you to create a library of raw HTML snippets you need to embed within post/page content, then uses the native shortcode API to embed them without them being auto-formatted by wpautop or wptexturize.

It may not be as convenient as pasting directly into the HTML tab of the WYSIWYG editor, but it’s a solution that’s reusable, clean and does not interfere with the core functionality of WordPress or other possible plugins/shortcodes/content filters.

Raw HTML Snippets | Download

Give it a whirl, and let me know what you think!

25 Comments

  1. Bob says…

    Hi Andy!

    Great implementation taking your rant into your own hands. Just one problem…when I try to edit a saved snippet, the changes don’t get saved. I need to copy the code, delete the snippet and recreate it.

    Also, a feature suggestion…add the option to load the full snippet instead of shortcode into a page or post via the html editor using a screen option with an implementation similar to the “Article Templates” plugin. That would allow someone to create snippets that require modification to transfer them directly into the editor (instead of copying from the raw html snippet plugin) and pasting in the editor.

    Will do it myself when I get time to uber vent that no one has come up with this keystroke/mouse click saver…lol…fyi I still use Article Templates for some things but it is a little buggy because it uses the editor and somehow seems to ignore wpautop disabling.

  2. andy says…

    @bob Good catch! I was moving too fast. Just updated the plugin to 1.1 which is just a bug fix for the editing of existing snippets. Watch out for it in the next 15-20 minutes when WP updates the repository.

    I like the feature suggestion, in the future I will be trying my hand at extending TinyMCE to have some full management capabilities for the snippets in there.

    In the short term, copy and paste will have to do until I find some more free time ;]

  3. Bob says…

    Thanks for the update Andy…you may want to take a look at “Post Snippets” implementation too for ideas. Personally, I don’t like their small size textbox for entry of snippets…need to copy (into a text editor), edit and repaste to see what you’re doing on long snippets. You’re headed in the right direction!

  4. Will Lanni says…

    Hey there,

    I implemented a bit of code where an <a> tag wraps around a block of content, including a <strong> tag and a couple of tags.

    Your snippet rendered out each line of text with the <a> wrapped around each P tag and the strong tag, resulting in three anchor tags, instead of just one.

    Just a bit of a bug.

  5. andy says…

    @will I just ran a test with the following code:

    <a href="#this-is-a-test">
    	So, let's
    	<strong>
    		see what this does <em>when I type it</em> into my
    	</strong>
    	<sup>
    		fancy little plugin
    	</sup>
    	…?
    </a>

    It rendered with no issues. I’d double check your theme, or send me an email via my contact form with the specific code.

  6. andy says…

    @will make sure your theme isn’t tainting shortcode output. Since this uses shortcodes, if your theme is falling victim to what I rant about here.

  7. Charlie says…

    Just what I was looking for – followed your readme file and was set up and running in about 2 minutes – thanks!

  8. j. millington says…

    Nice ‘lil plugin, just started using it a couple weeks ago .. Been working well to insert Google app iframes all over the place, but today, while editing/deleting/creating some snippets, I found that one of those snippets will not be deleted.

    Basically, I made a bunch of snippets for some Google Maps, but the naming structures were full of colons and spaces. I guess that wasn’t cool cuz when I added the matching shortcodes to my content, nothing showed up in the output. So, I re-made those snippets with a naming structure without spaces or colons (just underscores and hyphens) to get the output working, but, as I was deleting the old snippets, one of the old snippets won’t disappear after hitting the Delete button.

    I tried logging out and back in, I tried all three different instances of the Delete button (under the listing, right of the listing and in the snippet edit page), I tried re-starting my browser and also a different browser (Chrome and Firefox).

    I’m about to try uninstalling/re-installing the plugin, which I expect will work, but kind of annoying. Maybe you could work functionality that allows for changing names of snippets as a solution to such a problem? I know I wanted to rename a snippet before this even and found I had to make new/delete old just to do so :/

    Awesome plugin otherwise.

  9. andy says…

    @j can you give me example steps to re-create? I can probably quickly push a patch to the repository to clean this up (i.e. what is a sample snippet name that isn’t working)?

  10. j. millington says…

    For some reason I was under the impression that upon uninstall, previously created snippets would be deleted. so are these entries stored in the database then? I guess I’m off to find out…

  11. andy says…

    I’m pretty sure their stored as an option. I don’t have it delete them in case you re-install later and want your old snippets (no export, this was built very quickly).

    It sounded like you were unable to delete them via the plugin UI…

  12. j. millington says…

    sorry didnt see your reply there.. the un-delete-able snippet name is: “map: health & human services” with the shortcode: [raw_html_snippet id=”map: health & human services”]

    im in the database and i see an entry for the problem snippet in the wp_options table .. is there anywhere else i should be finding entries to delete?

  13. j. millington says…

    crap- deleting that row in the wp_options table did not remove the snippet from the list in the UI.

  14. j. millington says…

    ok i just noticed that the name of the snippet on top the edit page says only “map: health ” whereas any other snippet showsits name in the edit page exactly as it appears on the list page, only with quotation marks around it … something is definitely awry.

  15. andy says…

    Got it. Look for an auto-update in WP within 15-minutes ;]

  16. j. millington says…

    Nice. Did the update then successfully deleted the entry via the list page UI.

    Cheers, bro.
    😀

  17. Asaf says…

    Hi,
    First I want to say that it’s a great plugin. I use often without any hassle.
    What I wanted to know it there’s any way to ad a shortcode button to the editor, that a click on it will open a list snippets already in the system, that I can choose from?

    thanks

  18. andy says…

    It’s possible but I need to find some time to actually implement ;]

  19. Jess says…

    Great plugin! Is it possible to embed a snippet within a snippet? I have a piece of code that I need to use both alone as well as within another chunk of code. The client only wants to update one spot.

  20. andy says…

    Currently, no. This is an interesting request though, I’ll think about it. The issue with that is that I’m relying on the Shortcode API for embedding now. I’d have to write some overhead code (which may slow processing down) to recursively do this. I also would want to make sure it never results in an infinite loop, which would cause the site to timeout. Will think about this and let you know.

  21. Pascal says…

    I am just starting with wordpress.
    I find frustrating not to be able to put tags in my pages.
    I was hoping that I could use a tag in your snippets but it does not work.
    Am I missing something?

  22. andy says…

    Do you mean you want to tag your pages and have the tags display / view archives of pages by tag?

  23. Linda F says…

    Hi Andy, thanks for such a useful plugin. Is there a way to back up snippets and their code in the event they need to be restored them in the future? I’m saving all my code there and have no other backup yet so I’m concerned what might happen if somehow WP loses it all. Do the snippets get backed up in my WP db? Thanks, appreciate your advice!

  24. theandystratton says…

    @Pascal, try this in your functions.php file (or separate plugin) to enable category/tags for pages:

    @Linda you’re welcome! The snippets are stored in the wp_options table of your database, so if you’re backing up your WordPress installation you’re backing up your snippets.

    Does this help? I’d like to make some updates in early 2013 to all my plugins, perhaps I’ll try to add an import/export file.

  25. Marco Panichi says…

    Hi Andy,

    Thank you very much for your plugin…it’s what I needed!!!

RSS feed for comments on this post. TrackBack URL

Leave a Comment

May 12, 2011

Filed in Development, Plugins, Wordpress

There are 25 comments »


« Back to the Blog