Post Snippets

Description | Installation | Usage | Download | Translations | Filters | Changelog

Description

This admin plugin stores snippets of HTML code or reoccurring text that you often use in your posts. You can use predefined variables to replace parts of the snippet on insert. All snippets are available in the post editor with a TinyMCE button. The snippet can be inserted as defined, or as a shortcode to keep flexibility for updating the snippet. Also PHP code is supported for snippets inserted as shortcodes.

Some features:

  • Insert All defined snippets is inserted from a button directly in the post editor.
  • Shortcodes You can use this plugin to create your own shortcodes.
  • PHP A shortcode snippet can optionally be evaluated as PHP code.
  • Buttons The snippets are available in the viusal editor with a TinyMCE button and in the HTML editor with quicktag buttons.
  • Admin Easy to use administration panel where you can add, edit and remove snippets.
  • Import/Export Snippets can be imported and exported between sites.
  • Variables Each snippet can have as many custom variables as you like, which can used on insert.
  • Uninstall If you delete the plugin from your plugins panel it cleans up all data it has created in the WordPress database.

Installation

  1. Upload the ‘post-snippets’ folder to the ‘/wp-content/plugins/’ directory.
  2. Activate the plugin through the ‘Plugins’ menu in WordPress.
  3. Go to Settings -> Post Snippets and start entering your snippets.

Usage

The Admin Page

post-snippets-admin

Post Snippets Admin

Title

Give the snippet a title that helps you identify it in the post editor.

Variables

A comma separated list of custom variables you can reference in your snippet. A variable can also be assigned a default value that will be used in the insert window by using the equal sign, variable=default.

Example:
url,name,role=user,title

Snippet

This is the block of text or HTML to insert in the post when you select the snippet from the insert button in the TinyMCE panel in the post editor. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.

Example:
To reference the variables in the example above, you would enter {url} and {name}.

So if you enter this snippet:
This is the website of <a href=”{url}”>{name}</a>
You will get the option to replace url and name on insert if they are defined as variables.

Description

An optional description for the Snippet. If entered it will be displayed in the snippets popup window in the post editor.

Shortcode

Treats the snippet as a shortcode. The name for the shortcode is the same as the title of the snippet (spaces not allowed) and will be used on insert. If you enclose the shortcode in your posts, you can access the enclosed content by using the variable {content} in your snippet. The {content} variable is reserved, so don’t use it in the variables field.

PHP Code

Snippets defined as shortcodes can optionally also be evaluated as PHP Code.
Check this image for an example PHP snippet:

A PHP Post Snippet

With a snippet defined like the one in the image, you can call it with its shortcode definition in a post. The example snippet, named phpcode, would be called like this:

[phpcode loop_me="post snippet with PHP!"]

When the shortcode is executed the loop_me variable will be replaced with the string supplied in the shortcode and then the PHP code will be evaluated. (Outputting the string five times in this case. Wow!)

Note the evaluation order, any post snippet variables will be inserted before the snippet is evaluated as PHP code.
Also note that a PHP snippet don’t need to be wrapped in <?php #code; ?>.

wptexturize

Before the shortcode is outputted, it can optionally be formatted with wptexturize, to transform quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.

The Post Editor

Post Snippets Button

Post Snippets Button

With your snippets set up, you’ll find a new button in your post editor (circled in the image above), which you can click to open the Post Snippet window to insert one of your snippets in your post.

Post Snippets Insert Window

Post Snippets Insert Window

When you click this button, you get a window with all your available snippets. Each snippet has its own tab in the Post Snippet window, so you can select which snippet to insert. If you have set up custom variables for the snippet, you can now enter the values for these variables before clicking insert and they will be inserted in the correct places in the snippet string.

Advanced

You can add constants to wp-config.php or the theme’s functions.php file to control some aspects of the plugin. Available constants to set are:

// Allow users with edit_posts capability access to the Post Snippets admin. 
define('POST_SNIPPETS_ALLOW_EDIT_POSTS', true);

// Disable PHP Execution in snippets, and removes the options from admin.
define('POST_SNIPPETS_DISABLE_PHP', true);

You can retrieve a Post Snippet directly from PHP, for instance in a theme, by using the PostSnippets::getSnippet() method.

Usage

<?php $mySnippet = PostSnippets::getSnippet($name, $variables); ?>

Parameters

$name
(string) (required) The name of the snippet to retrieve.

$variables
(string) The variables to pass to the snippet, formatted as a query string or as an associative array.

Example

<?php
    // Use querystring for variables
    $mySnippet = PostSnippets::getSnippet('internal-link', 'title=Awesome&url=2011/02/awesome/');
    echo $mySnippet;

    // Use array for variables
    $mySnippet = PostSnippets::getSnippet('internal-link', array('title' => 'Awesome', 'url' => '2011/02/awesome/');
    echo $mySnippet;

?>

Download

The Post Snippets install archive is available from the WordPress Plugin Directory. The download link below directs to the plugin page where the latest version as well as all older released versions of the plugin can be downloaded.

Translations

Other than the default English language, Post Snippets has been translated to the following languages:

Filters

The following filters are available for hooking into the plugin:

  • post_snippets_import serialized array Modify snippets and related data before the imported file populates the snippets.
  • post_snippets_export serialized array Modify snippets and related data before the export file is created.

Examples

post_snippets_export

// Filter Exported Snippets
function ps_export( $snippets )
{
  $snippets = unserialize( $snippets );
  foreach ( $snippets as &$snippet ) {
    // Do something here. Example below search and replaces in snippets
    $snippet['snippet'] = str_replace('search','replace', $snippet['snippet']);
  }
  return serialize( $snippets );
}
add_filter( 'post_snippets_export', 'ps_export' );

post_snippets_import

// Filter Imported Snippets
function ps_import( $snippets )
{
  $snippets = unserialize( $snippets );
  foreach ( $snippets as &$snippet ) {
    // Do something here. Example below search and replaces in variables
    $snippet['vars'] = str_replace('search', 'replace', $snippet['vars']);
  }
  return serialize( $snippets );
}
add_filter( 'post_snippets_import', 'ps_import' );

Changelog

See the plugin’s Changelog at WordPress Codex.

Liked this page?

Subscribe to the site feed with RSS or by email.

Comments

  1. MartinRMarch 24, 2009

    great plugin.
    works like a charm.

    Thanks
    Martin

  2. javierApril 2, 2009

    Hello there,

    This plugin rocks!! It makes life much easier than flutter and it has a similar function. (At least as for what I want to use it for).

    Just one little thing, I have a couple of blogs (both wp 2.7.1 running in the same server) and meanwhile in one of them it works just fine I am getting a error in the other one, the thing is that when trying to insert the lightbox does not disappear by itself and afterwards when y close it myself there is nothing in the text-area.

    Have you ever run in such an error? Any ideas about what it could be?

    Thanks a lot!!

    PS: I also deactivated all my other plugins and seems not to be the problem as it didn’t solve the problem.

  3. JohanApril 2, 2009

    Hey Javier,

    I am happy you find this little plugin useful.

    I’m working on a new version, as I came up with a few more ideas for more flexibility, and I’ll make sure to address your problem as well.

    I have an idea what the cause might be for your problem, but to make sure I really catch I’d need some additional information. If you could drop me a mail at http://www.artstorm.net/contact/ I’ll get back to you, or I’ll see if I can reach you at your site.

    Cheers!

  4. YMApril 14, 2009

    Hi,

    Very nice plugin. Haven’t been looking for something like this for a long time! I get a javascript error on some strings when using the QT option.

    just thought i’d let you know about the bug.

  5. JohanApril 14, 2009

    YM:

    Thanks for the report. I think I know what might cause your problem on some occasions. I’ll take a look at it tonight and issue an update with with the problem corrected.

    -Johan

  6. ChrisApril 15, 2009

    This is one of the most useful and versatile plugins I’ve come across and I want to thank you for your efforts!

    I’m setting up a new blog and just installed Post Snippets tonight to give it a quick test. I’m running WP 2.7.1 and I don’t see the “quicktag” option when trying to insert code in HTML mode. I thought I might need to have both the QT and SC boxes checked in order for the quicktag option to display, but when I checked both, updated the snippet, and clicked to add a new post, I get an error thrown at the top of the page. After a few moments I get a run-time error displayed in the editor as well. Here’s what’s at the top of the page:

    Parse error: syntax error, unexpected T_STRING in [name of my blog]/wp-content/plugins/post-snippets/post-snippets.php(102) : runtime-created function on line 6

    I’ve inserted [name of my blog] where the path to my blog was reported. Hope this is helpful, and I look forward to the continued growth of this very promising plugin!

  7. JohanApril 16, 2009

    @YM and Chris: I just updated Post Snippets to version 1.4.3 and it should be available for download. I believe this update should take care of all problems related to quicktags and certain strings, and should solve both of your problems. If something still persists, let me know.

    Cheers!

  8. baronApril 16, 2009

    Works great, thank you

  9. Poker&MoreApril 16, 2009

    GREAT JOB !! Thank you !

    Next step One button per Snippet ??? :-)

  10. ChrisApril 19, 2009

    Johan -

    Thank you for being so pro-active on this! I just downloaded and installed vers. 1.4.3, but I’m afraid I’m still not seeing a “snippets” option in the HTML view of the post editor. There’s a nice little icon that appears for the Visual view, but no new button in the HTML view. The errors I was seeing thrown before seem to be fixed, however.

    I may be missing something, but this is what I’m seeing:
    http://www.practicingkinetics.com/snippets/

    For the record, I’m on a Mac, editing WordPress vers. 2.7.1 in either Safari 3 or Firefox 3

  11. JohanApril 19, 2009

    Chris,

    Thanks for your screenshot. That helped. :)
    I see what I missed and what the problem is. I am just about to call it a night here, but it’s an easy fix, just a stupid mistake I made in the last update. I’ll post a new version tomorrow that should have this resolved as well.

  12. ChrisApril 20, 2009

    The new fix works a treat! Thanks for all your extra effort over the last couple of days. I dropped some coin into your donation jar to show my appreciation, and I look forward to any other future additions you have in store for this great little plugin.

  13. ShaneApril 23, 2009

    I’m using this plugin to add a contact form to the sidebar of a specific page, but when I copy/paste the HTML for the form into the snippet and save it the code gets cut off just above the submit button, and it appears that instead of it being a part of the snippet it then renders the submit button below the textarea for the snippet code. When I add the snippet to a page, the HTML stops at the same point and fails to output the entire form. Is there a way to instead add in PHP to the snippet so I can instead include a PHP file with the form HTML? I tried adding a typical php include to the snippet and it just renders it as text.

  14. JohanApril 23, 2009

    @Shane: If you have the time, feel free to send me the form html and I’ll take a look at what the problem might be. You can send it to me at http://www.artstorm.net/contact/

    And about adding PHP code in a snippet, it’s currently not possible as the plugin treats everything as strings. But it was an interesting idea, and I’ll look into adding that as an optional setting for each snippet in the next update.

  15. JohanApril 24, 2009

    @Shane: I just released version 1.4.5 of the plugin, and it should solve the problem you were seeing. Thanks for your report and feedback. :)

  16. MorseFireApril 27, 2009

    oooh man … this is beautiful!

    it’s an essential function that i really missed in wordpress. expression engine and modxcms do have these functions but i always wished to see them in wp too. thanks so much!

    btw … i’m sure you are familiar with ee and modx. if not, there you’ll find many ideas how to improve the functionality of your plugin.

    greetings

  17. ShaneApril 27, 2009

    Thanks for the quick update, however on my WP install once I update the plugin I get the same error no matter what code I’m entering in to the snippet, and it clears out all of my other snippets. I’ve also tried completely uninstalling and reinstalling the plugin but am getting the same issue. The error I get is: “Warning: htmlspecialchars_decode() expects parameter 1 to be string, NULL given in /homepages/30/d280197016/htdocs/wp/wp-includes/compat.php on line 105″

  18. JohanApril 27, 2009

    @shane: Ah, thanks, I know what it is. I guess you’re on a webserver that’s running on PHP4. I didn’t consider that the htmlspecialchars_decode command I added in the last update requires PHP5.1+. That’s why WP throw that error, when used on a server using an earlier PHP version – it actually should work anyway, but WP 2.7 has a bug in that particular function.

    As it’s a common function, WordPress tries to add it’s own _decode function when using PHP4 so plugins using the htmlspecialchars_decode will still work on pre-php5.1 installs, but checking the compat.php in the 2.7 wordpress install I see a variable typo in that function, so that’s why it throws the error, even though it shouldn’t. I’m gonna check out if this bug is fixed in WordPress 2.8, otherwise I’ll trac it.

    In the meantime, I’ll add my own function to the plugin that switches to an older method of converting the characters if a pre 5.1 php version is detected. I’ll fix that tonight.

  19. ShaneApril 27, 2009

    I was actually just thinking that when I was tracing the error back to see whether or not the string given was actually null. I had forgotten that, while 1and1 has PHP5 installed on their basic hosting, you need to activate it. It’s strange that the latest WP works on PHP4, I would have thought they’d abandoned its full support by now.

    I’ll switch it to PHP5 and let you know if I still have issues. It’s funny how you’re able to find the bug in the WP code so fast and come up with a fix for it. You must be quickly becoming a valuable contributor to WordPress!

  20. JohanApril 27, 2009

    @MorseFire Thanks for your nice words, I appreciate it! :)
    And well, I haven’t checked out expression engine and modxcms, but when time permits I’ll do that, and see if I find any nice features that would be suitable for adoptation in Post Snippets.

  21. JohanApril 27, 2009

    @Shane I just uploaded version 1.4.7 of the plugin to the WordPress plugin repository, where I’ve added a check for the server’s PHP version and revert back to another html decode function if it’s below v5.1.0. That should do the trick for older servers.

    And the bug in WordPress wp-includes/compat.php that caused the problem is patched for version 2.8. :)

    I’m learning a great deal about WordPress while developing this plugin so I really appreciate all reports, so I can make it as stable as it can possible get, and take that knowledge with me to other plugins I might write down the road.

  22. Tom BrazeltonApril 30, 2009

    I’m getting a weird error when I try to create a new snippet:

    Warning: htmlspecialchars_decode() expects parameter 1 to be string, NULL given in /home/.katsumi/thopper/theaterhopper.com/wordpress/wp-includes/compat.php on line 105

    The button appears on the new post page, but it doesn’t appear to retain the code I put in the snippet box.

    Any advice?

  23. JohanApril 30, 2009

    @Tom Are you using the latest version of Post Snippets? V1.4.7? The problem you are seeing is caused by a bug in the WordPress core in v2.7.x when run on a server using an older PHP version (Fixed in WP 2.8).
    I added a workaround in the latest version of Post Snippets so it should work properly in that environment as well. So if you aren’t running the latest version (v1.4.7), try to update to that one. If that doesn’t help, please let me know and I’ll take another look at it.

  24. Tom BrazeltonApril 30, 2009

    Johan – that has to be the fastest reply to a WordPress plugin question ever. Thanks!

    I grabbed 1.4.7 from the WordPress Plugins website, but I actually found another solution.

    Nothing against your plugin, but I found this article about adding custom buttons to the post editor by hacking the wp-includes/js/quicktags.js file – http://tinyurl.com/84r4f6

    Thanks again, though, for your prompt response!

  25. MomoMay 2, 2009

    Thanks for the great plugin. I have a question. I’m trying to set up a wp blog for a customer. It has a Amazon plugin that uses this HTML format to search for products….

    You can only see and modify this on the HTML tab of the editor. The HTML view is too confusing for the customer.

    I downloaded your plugin and used the SC option to allow the customer to change the attributes in Visual mode. It fills in the attributes perfectly, but the shortcode does not work.

    It “echos” on the web page, but it does not process it. I need it to process it and then render the page. If you add this code in HTML view on WP, everything works fine.

    How can I get it to process the shortcode generated by Post Snipplets.

  26. Ryan MitchellMay 3, 2009

    Great plugin! Having an odd problem. When I click the “Insert a Post Snippet” button, it brings up the window to add in variables but it is empty. That is in Firefox.

    Tried it in Safari and it does the same then downloads window.php

    Perhaps it is the server this site is on, but I’m stumped!

  27. JohanMay 3, 2009

    @momo and @Ryan Thanks for your comments. I have emailed you for some additional information, so if you get the time, please send me the snippets or a screenshot and I’ll see what the problems might be and issue an updated version if necessary. :)

  28. s1lviiiMay 10, 2009

    Hey!
    I just downloaded your Post-Snippets-PlugIn as it is exactly what I was looking for. When I want to add a Snippet it says: “Warning: htmlspecialchars_decode() expects parameter 1 to be string, NULL given in /home/www/web27/html/wordpress/wp-includes/compat.php on line 105″ … it also says: Snippets have been updated. – but the field with the code of the snippet itself stays blank … it does not apply my changes (it’s an html code that works in the editor itself but I just don’t want to type it over and over again ;x) … the fields with the title of the snippets and the variable does work, but that does not help me :D

    Can you help me with this? :)

    Best regards,
    Silvia

  29. JohnnyMay 16, 2009

    Hey Johan,

    Love the functionality this plugin will provide, but I’m running WP 2.7.1 and downloaded v. 1.47 of the Post Snippets plugin, and I’m having the same problem with compat.php that @Tom and @momo have described above.

    Please let me know if you can help. :)

    Thanks!
    Johnny

    1. JohnnyMay 16, 2009

      Nevermind, I found the problem. I upgraded my PHP version to 5.2 (from 5.0) and everything works perfectly!

      Great plugin!

      1. JohanMay 23, 2009

        Happy to hear that it worked out for you! :)

        I will change that function for the next release though to not rely on the newer PHP functions, as the rest of the plugin doesn’t need PHP above 5.

  30. MarkMay 21, 2009

    Just installed 1.4.8 and using quick tags. However I keep getting the following error in the Javascript Console (Firebug) as well as an alert box:

    invalid quantifier +);});
    } catch (e) {
    if (e != $break) {
    throw e;
    }
    }
    return this;
    }}
    http://blog.mcstudios.net/wordpress/wp-admin/post.php?action=edit&post=568
    Line 1113

    That line refers to :: var re = new RegExp(searchfor, ‘g’); in your code.

    Any thoughts? The snippet I’m using doesn’t have any variables, so I’m not sure why it’s entering that code.

    1. JohanMay 23, 2009

      Hi Mark,

      Thanks for your comment.
      I’ve had some problems with the quicktag implementation in certain situations. I think I know what’s causing your problem. I’ve completely rewritten the quicktag function for the upcoming version 1.5 from the ground, which will be completely solid when using quicktags.

      Stay tuned and version 1.5 will be released very soon, I am certain that and the following versions won’t have any quicktag related problems anymore.

    2. MaxApril 26, 2010

      a quick fix would be to edit:

      /wp-content/plugins/post-snippets/post-snippets.php

      and replace (around line 192):

      postSnippetsButton.onclick = function () {edInsertSnippet(edCanvas, insertString<?php echo $i; ?>, variables<?php echo $i; ?>, parseInt(this.title));}

      with

      try {
      postSnippetsButton.onclick = function () {edInsertSnippet(edCanvas, insertString<?php echo $i; ?>, variables<?php echo $i; ?>, parseInt(this.title));}
      }catch(err) {
      //Handle errors here
      }

  31. David HawdaleJune 8, 2009

    I’m having problems with using it in Safari on Mac. The overlay overlays the Dlg box as well as the screen, cant click. Works fine on FF on Mac. But it would definitely be worth a pint for Safari ;-)

    1. JohanJune 9, 2009

      Thanks for your report.
      WordPress 2.8 is supposed to be released tomorrow if nothing unexpected happens. I have a new version of Post Snippets that will be released shortly after that, where I among things have changed the way the dlg box is created. I’ll see if I can try it on Safari and a Mac before releasing it to see that there isn’t any problems there.

  32. MileHighTechGuyJuly 2, 2009

    Hi. Great plugin. It works great with HTML.

    Does it work with JavaScript snippets? (or PHP?)

    1. JohanJuly 2, 2009

      Hi,

      It should work fine with JavaScript. PHP wouldn’t get executed but treated as ordinary text instead. I have been thinking of adding that as an extra option though to be able to add PHP code that would be evaluated on runtime.

  33. sergioJuly 5, 2009

    I wonder if there’s any way to prevent the code in the snippet being URL encoded. e.g. I’m using it to build a custom Youtube object (with my color set) and the params separated with an & appear as & instead.
    It’s been working so far, but I wonder how to fix it.

    Thanks.

  34. sergioJuly 5, 2009

    Sorry, my ampersand appear the same in the post above. I meant the common & amp ; encoded ampersand apears instead of the symbol alone, as the params separators in the youtube url (hopefully Youtube handles it anyway)

    1. JohanJuly 5, 2009

      Ah, I see. I do believe the & amp ; actually is the preferred way and should work fine with youtube. But if it doesn’t I could add an option so one can decide how content should be encoded/decoded. Having it working with youtube etc is a nice use of the plugin, so let me know if the current encoding should cause any problems and I’ll take a look at how to make such a choice in a userfriendly way from the admin panel.

  35. NecatiSeptember 18, 2009

    How can I go about setting predefined snippets?
    Which part of the code should I hack for this?

    Thanks.

  36. MarioSeptember 21, 2009

    This plugin is awesome. Just what I was looking for! Thanks!

  37. LeahOctober 8, 2009

    Great plugin!!! What a timesaver. This also allows you to bypass the main stylesheet if you need to have a snippet use custom styles. Plus so far anything I’ve had to ‘snippetize’ looks good in all the major browsers, even the dreaded IE6.

  38. Phil LenchNovember 10, 2009

    Hi Johan.

    Is it possible to allow the snippet to be suspended and still leave the shortcode in the post but not show.

    The reason I ask is because my Netbook site uses voucher codes issued at irregular times by merchants and when one code ends and I wait for a new one to be issued I want to be able to make the snippet vanish for a while and then get re-shown once re-activated.

    At the moment the snippet still shows and I have to remove the shortcodes instead to get around the problem.

    1. JohanNovember 16, 2009

      Hi Phil,

      Good one. That’s a useful feature you suggested. I’ve added it on my todo list for the next version.

  39. Phil LenchNovember 18, 2009

    Thanks Johan.

    I have got round the problem slightly by making a snippet for each merchant and then putting the text “Sorry, no voucher available” into it.

    The appropriate shortcode is placed in every post and when a voucher code does go live then I just put the voucher text in and update.

    Not very elegant but it works. Just not too keen on seeing a “No voucher” snippet on almost every page.

    This page, http://www.yournetbook.co.uk/ubisurfer-netbook/ has the Maplin shortcode in place and working.

    I would still rather have a ‘suspend’ button though.

  40. Rich OwingsDecember 22, 2009

    Is there any way to use this in templates? Can I just drop a short code in there?

    1. JohanDecember 29, 2009

      Rich,

      My first thought is no, but I am not entirely sure what you are trying to do. What was your intention by using this in a theme, perhaps it can be done if I know a little more.

      Cheers!

  41. Rich OwingsDecember 29, 2009

    Thanks for your response!

    I’d be using it to insert code for ads, and be able to make a change sitewide. By using it in a template, I could insert the short code above the title or below the post, but be able to make sitewide changes in the content that it calls.

    I’m also playing with the Sniplets plugin, which seems like it will do it, but I’m having trouble with custom placements.

  42. RyanJanuary 2, 2010

    What kind of snippets do I actually need?

    I’ve looked at the picture of the post snippet but i’m not sure if it can solve my blog problem.

    Cause right now, whenever anyone view my blog, the blog which i don’t know for what reason and settings will show the full blog entry instead of just a section or parapgraph of the entry.

    I have edit the settings to show only the summary but it’s not helping.
    Will this Post Snippets help solve my problem?

    1. JohanJanuary 2, 2010

      Hi,

      No the Post Snippets plugin let’s you created small snippets of for instance HTML code, which is useful if you have some code you need to insert over and over again. Then you can make a snippet of it to save some time and make it more convenient. So it won’t solve that particular issue.

      The function you are looking for to not display the entire entry on the post listing page is to use the more tag. It’s a built in function in WordPress. An icon to insert the more tag is available in the post editor, I think it’s the fourth icon from the right in a standard WordPress installation, and then the content below the more tag will only be displayed when you visit the actual post page and not in the post listings. Providing the theme supports this option, but most themes do.

      Cheers,
      Johan

  43. EricJanuary 21, 2010

    Hi, thanks for the grat plugin, really beneficial for repeated content etc. I have one specific question:

    I am using both your plugin as well as the ‘category order’ plugin (By Wessley Roche). The my categroy plugin is a drag and drop category ordering plugin. The issue is that when both plugins are active the category order ajax interface stops working (cannot drag and drop anymore). Deactivating Post Snippets makes it work again.

    The error I get in Firebug is this:

    Error: postSnippetsButton is null
    Source: http://www.vliegticket.com/wp-admin/edit.php?page=wpguy_category_order_options&childrenOf=0
    Regel: 90

    This part of the code is highlighted:
    postSnippetsButton.onclick = function () {edInsertSnippet(edCanvas, insertString0, variables0, parseInt(this.title));}

    So it seems these two somehow interfere.

    Is there anything I can do about this you think?

    Kind regards, Eric

    1. JohanJanuary 22, 2010

      Hi Eric,

      Thanks for the report. It does seem indeed that there is some collision between the two plugins. And I’ll have it fixed in the next update.

      I’ve version 2 of the plugin in the works, with a complete rewritten function for the post editor overlay window for post snippets, which will take care of this and any other javascript related collisions.

      I’m just a bit busy with my regular work right now, but I hope to be able to get some time soon to get the new version finalized. :)

      Cheers,
      Johan

      1. EricJanuary 24, 2010

        Sounds good Johan, thanks for the quick reply. Looking forward to the update!

        Kind regards, Eric

  44. hiteshFebruary 23, 2010

    thank you man i love it

  45. ToneMarch 16, 2010

    Great plugin!!

    But, I’m struggling with the use of parameters in shortcodes. Have a look at the setup shown in this picture: http://www.vrtifacts.com/shortsnippet.jpg

    In the Post Snippets Settings area, I create a snippet called “GoogleURL” with a single parameter “URL”. The snippet is: A Google Page

    I check the SC and QT boxes and Save these settings.

    I then create a post; use the quicktag which inserts [GoogleURL URL=”intl/en/about.html”

    Trouble is: when I view the post on the website, the parameter for the URL is missing; the HTML source the displayed page is: A Google Page

    My parameter substitution wasn’t inserted.

    What have I done wrong? I’m sure it’s something silly, but….

    Thanks

    1. JohanMarch 16, 2010

      Hey Tone,

      WordPress automatically convert shortcodes attributes to lowercase before executing them. So just update your snippet to use lowercase for the variable and you should be set. :)

      Ie. Change the variable field from URL to url
      And change your snippet code to

      <a href="http://www.google.com/{url}" rel="nofollow">A Google Page</a>
      

      So it says {url} instead of {URL}

      I should probably add a automatic conversion to lowercase in the plugin, but for now the above will fix your problem.

      Cheers,
      Johan

      1. ToneMarch 16, 2010

        Kewl! That works! Thanks for the quick response and awesome plugin!

  46. ToneMarch 16, 2010

    Hi Johan,

    Anything I should do to be able to nest shortcodes? I’m using other plugins which employ shortcodes. I would like to embed those shortcodes in my snippets and then create shortcodes for my snippets. So far it’s not working; your plugin translates the snippet shortcode into the shortcode for the other plugins, but the other plugins don’t translate their own shortcodes anymore.

    I don’t know of WordPress handles nested shortcodes. Or maybe this issue relates to the priority for the different plugins which use the shortcode expansion hook? Perhaps I can set your hook to a higher priority?

    Thanks!

    1. JohanMarch 16, 2010

      WordPress supports nested shortcodes, but the shortcode must support it as well.

      If you don’t mind adding a little something to the plugin code, you only need to add one line to make it support nested shortcodes.

      If you track down the function create_shortcodes() in the plugin, and at the bottom of that function you have it ending with a line saying:

      return stripslashes($snippet);’) );
      That’s approximately around line 104 in the code.

      Add this line just above it:

      $snippet = do_shortcode( $snippet );
      

      And wordpress will run any shortcodes contained inside the snippet before returning your snippet to WordPress.

      Cheers,
      Johan

      1. ToneMarch 17, 2010

        Johan,

        Almost….

        In addition to the extra bit of code you suggested, the line:

        return stripslashes($snippet);’) );

        needs to be changed to:

        return $snippet;’) );

        as do_shortcode has stripslashes already.

  47. DanMarch 17, 2010

    For some reason I can’t get the variables to show up. I have the latest version and also wp 2.9.

  48. DanMarch 17, 2010

    Never mind, got it! This is so much better then using custom fields… thank you

  49. Dennis RiversMarch 29, 2010

    Thanks for the great plugin. I am building a complex site and will eventually have 60 to 100 snippets. Is there any way that I can periodically sort the stack of snippets into alphabetical order.

    1. JohanMarch 29, 2010

      Dennis,

      Currently there is no easy way to sort the stack of snippets without going in and adding some additional code to the plugin.
      That’s a good option to have though, I’ll add it to the next update of the plugin.

      Cheers,
      Johan

  50. NiallApril 13, 2010

    Excellent plugin. Initially I thought that wordpress would have come with such a time-saving feature.

    I have a few suggestions though.

    It would be nice to upload images through the snippet lmodal window so a client doesn’t have to get dirty with html

    It would also be cool to have some template features for the code snippet (ie if/else/for)

    Though i’m not an idiot and I understand that both of these could/would require alot of work.

  51. John R PatrickMay 9, 2010

    Very nice plugin. Been looking for something like this. I installed it and it works fine for entering simple text. How do I add html code? I tried to use it to enter some sharethis code for me. The yellow icon is only on the text page not on the html page. How can I use this plugin to insert html? What I am trying to enter is the following….

    //

    1. JohanMay 9, 2010

      John,

      WordPress seems to have stripped the html snippet out from your comment. But generally speaking, the plugin shouldn’t have any problems at all dealing with html, that’s what I’m using it for myself.

      You could email me the html via the contact page and I can take a look at it what the problem might be.

      Cheers,
      Johan

  52. iplntsMay 10, 2010

    Hi Johan!

    That’s a great life-saving plugin. Thanks for it!

    A tiny problem I observed:

    When I deploy my local site to another host (and after when typically replacing the new host name in the database.. etc) on the new host I lose all previously set snippets.

    Could you help me – please how can I resolve this? (That’s a bit embarrassing to rewrite all snippets as many times I may deploy my site to an other host, although the settings are kept in the database :(

    1. JohanMay 13, 2010

      Hi,

      An import/export option for the snippets would be a great option. Thanks for bringing that to my attention. I’ll make sure to add something like that to the next version.

      In the meantime, if you check your database’s table (prefix)_options, you’ll find a row in that table called: post_snippets_options
      You can copy that row or manually add a row in your new database’s _options table called post_snippets_options and then copy the content in the option_value field from the old to the new db.

      Cheers,
      Johan

  53. John R PatrickMay 11, 2010

    Left you more detail at your contact page. Please let me know if you got it. Thanks.

  54. GregMJuly 11, 2010

    Hi Johan,

    This is incredibly handy — thanks!

    One suggestion: if you wptexturize the output before returning it at line 104, snippets inserted via shortcodes gain the usual typographical niceties like curly quotes, etc.

    Also, I haven’t looked in detail, but I wonder whether the ampersand replacing in that same section of code might be handled instead by decoding specialchars and then re-encoding specialchars? The point of that would be to enable folks to include things like HTML entities in their snippets, which cannot be done when all ampersands get escaped via a direct str_replace. Just a thought!

    All the best,
    Greg

  55. kalimeroSeptember 13, 2010

    Hello, i just love this plugin. But it is possible to keep the pre-formatting of the snippet when inserting via quicktag into tinymce?

    I have a snippet thats like:

    Change text for whatever

    Change text for heretoo

    When i go back to the snippet admin page its preformatted like i did it, so i wonder if isnt possible to keep it in the tinymce editor too.

    1. JohanSeptember 17, 2010

      Kalimero,

      I just updated the plugin to v1.5.2 and I think it will now do what you were looking for.

      Cheers,
      Johan

      1. kalimeroSeptember 17, 2010

        Thanks Johan!

        Just got your mail and installed the new version of your plugin, works like a charm! Great work.

  56. GarySeptember 25, 2010

    Fantastic plugin. HUGE time saver. Where’s your donate button? ;-)

    One thing that’s missing is the button to see all the post snippets when using HTML view (which I always use). It’s there on the Virtual view, but not HTML.

    Would be nice to pull snippet lists while staying in the HTML view.

    Thanks!

  57. Wendy McManusSeptember 30, 2010

    Hi there! This is a very cool plugin! One issue we are having is that the tabs don’t wrap in the TinyMCE editor in IE7. Works great in other browsers, unfortunately our customer is still using IE7. Thought you should know, and if you know how to fix it that would be super!

  58. GuyOctober 23, 2010

    Great plugin. Is it possible to include wordpress user fields such as the user’s name as entered by the user?

    This way I could create a snippets such as Welcome back [user's_name].

  59. TimNovember 11, 2010

    Hi, not sure if I am using it right, but when I click on the snippet name [signup-form] it inserts the text [signup-form].

    But when I look at the actual post, it doesn’t substitute the text it just displays [signup-form].

    I had both SC and QT checked….am I missing something?

  60. TimNovember 17, 2010

    How do I assign, as in your example, the variable values? Would I use something like exec PHP and assign the value in the page url = “http://www.domain.com”?

    1. johanNovember 17, 2010

      Tim,

      Currently is executable PHP code not supported. It’s something I’m considering to add though.

      Cheers,
      Johan

      1. MattiasJanuary 19, 2011

        Ah, that’s why it doesn’t work for me.
        I have a movie rating plugin that uses executable php code and doesn’t have any own shortcodes to list all the movies, but have the function.
        It works within a text widget in a sidebar but wordpress doesn’t execute php code in pages, so I hoped this was my savior, because I can’t really code and making own shortcode for it seem like a big job for me.
        It would be nice if you just not considering it, but doing it.
        It would be really appreciated.

        1. JohanJanuary 20, 2011

          Hallå Mattias! Schysst filmsida du har på g!

          And in english:
          That feature is currently high in my to-do list of stuff to implement, I’ve got several similar requests.

          So it will happen. I’m not sure how soon though.

          My day job keeps my way to busy at the moment so I have somewhat of a hard time right now to get a new version out the door, but when it settles I’ll push it out.

  61. paulJanuary 6, 2011

    great plugin, I have rated it on WP.org.
    is it possible to have textarea fields in the popup ?

  62. nohlJanuary 24, 2011

    Is there a way to have shortcodes get processed? It’s not working for me.

  63. SimonFebruary 1, 2011

    May I suggest one improvement to this plugin — if the the shortcode is empty then allow other shortcodes from other plugin(s) to run instead.

    To my knowledge there is no shortcode priority — two shortcodes with the same name compete. It is nice to allow theme authors / plugin authors to evaluate the parameters for the shortcode themselves.

    http://pastebin.com/aE6N2GpJ

    Great plugin btw!

  64. SimonFebruary 10, 2011

    1. JohanFebruary 26, 2011

      Simon,

      I just replied in the thread over at Codex. I’ll add your suggestion in the next release (v1.7.1).

      Cheers,
      Johan

  65. DonnaFebruary 17, 2011

    Hey Johan, this plugin rocks! Thank you so much for creating and maintaining it.

    I was wondering if you would be interested in doing a slight customization for us, and how much it would cost? If it would be possible for you to add php template tags for to a customization of the plugin. That’s what I see them referred to as, but basically a way to call a snippet with either a shortcode (as PostSnippets already does) or a php function call e.g. http://pastebin.com/4nY1caCv

    If can, and are interested in doing this can you contact me via email so we can discuss how much it would cost etc?

    Thanks,
    Donna

  66. FrankFebruary 22, 2011

    This looks like a terrific plugin, but its usefulness to me is greatly diminished by its mangling of urls that contain ampersands. For example, I’d love to use this snippet to link to ebay auctions:

    {Text}

    But switching to html view in the editor I can see that each & has been replaced by {ampersand character}amp;, which breaks the url.

    I see I’m not the first person to mention this. It seems to me that html entities entered into the box that pops up asking for {ID} and {Text” values should be converted, but the snippet itself should be inserted *exactly* as entered.

    Any chance of a fix?

  67. BracollaFebruary 25, 2011

    Great plug-in, very useful.
    Sorry to say it stopped working after upgrading to WP 3.1

    1. JohanFebruary 25, 2011

      Completely stopped working? It works on the site I use it on myself since upgrading to 3.1.
      Or is it just some specific functionality that doesn’t work for you?

  68. BracollaFebruary 25, 2011

    Thanks for the quick reply.
    Neither the quicktags nor the shortcode seem to work.
    The admin page is still there but post snippet buttons are gone.
    Tried deleting and reinstalling the latest version but to no avail.

    1. JohanFebruary 25, 2011

      I’m on it! I’ll have a new version ready in a few hours that updates the Quicktags part of the plugin and makes it work with 3.1.

      Thanks for the report.

      Cheers,
      Johan

  69. Melvis LeonFebruary 26, 2011

    Hello, I update my spanish translation (v.1,7), where do I send it?

    1. JohanFebruary 26, 2011

      Just drop me a line on the contact page here and I’ll get right back to you.

      Cheers,
      Johan

  70. BracollaFebruary 26, 2011

    Fantastic, the new version works like a charm.
    Thanks again for this great plug-in.

  71. GaryFebruary 26, 2011

    Thanks for updating this so fast. Love the plugin, but love the previous version better! Is it a WP 3.1 issue that the individual snippet buttons are gone? New version has “one” button (to rule them all, I suppose) versus the 10 I had before. Extra step to access the snippets, plus don’t like losing sight of the text/codes to choose the snippet. Not sure if this was by your design or WP limitations, but thought I’d mention it.

    1. JohanFebruary 26, 2011

      Yes, that is completely my “fault” and by design.

      The reasoning why I did this change is that I’ve had too much problems with how I did my old Quicktags implementation and have wanted to rewrite it for quite some time, so when WP3.1 finally broke the old one it was a good moment for me to take the time to rewrite it, as the quicktags had to be fixed for 3.1 right now anyway.

      I’ve had conflicts between the storage of snippets and how they escapes special characters between TinyMCE’s editor (Visual mode) and the Quicktag editor (HTML) mode, which has caused problems, and most important of all – have held me back moving the plugin forward feature wise in the pace I would have liked it to.

      So now I’m implementing my own jQuery UI window to deal with the insertion of snippets, and this new UI window will also replace the TinyMCE window that’s been used since v1 in the Visual Editor. So I get a consolidated code that behaves the same no matter if you work with the HTML editor or the Visual Editor. Much easier to maintain and update for me.
      I could of course kept polishing the old turd, but at the end of the day, it’s still just a polished turd, with workarounds between the different editors.

      In all fairness, my initial quicktag implementation was overly complicated, and now when I redid it, it turns out to be much simpler, so I can bring back the quicktags as separate buttons down the line, sharing the new code with the jQuery window, ie. no conflicts, and only one place for me to maintain.
      That would in that case be an option in the settings (Something like: [checkbox] Use window or separate buttons for quicktags).

      But first I’ll complete the transition to my own jQuery window shared between the HTML and the visual editor for consolidation and code consistency, and add some longstanding feature requests.

      And also add some more improvements to the new dialog window to make it easier to work with.

      But then I for sure will look into adding an option to be able to choose between separate buttons or a window for the HTML mode. I’m well aware of that there is a bunch of users that prefer it that way. But I had to do this move sooner or later to clean up the old quicktag code and make the plugin a step closer to being as rock solid as possible.

      So that’s how my forward looking plan is right now for the plugin, I hope that helps with why I did this change for the time being. :)

      Cheers,
      Johan

      1. GaryFebruary 26, 2011

        Thanks for the extensive explanation. Makes sense! Shiny turds have some use I suppose, but…anyway, I also wonder if my gut-reaction (and likely others) mostly falls in the “oh no, the old way was (fill-in-the-blank).” I will no doubt come to accept, nay, even love, the one-button approach. And to keep things in perspective, 1) the plugin is free, and 2) all those who complain should refer to item #1. :-)

        Appreciate your efforts! And totally understand getting control of the code. I can only imagine the nightmare it can be to keep up with various changes on all the externals that affect a plugin’s code!

        1. JohanFebruary 26, 2011

          Gary,

          I thought I better write down my plan somewhere now when I did this change so I just can link to that comment instead of repeating myself. :D

          Thanks for the interest!

          Cheers,
          Johan

  72. YerbFebruary 27, 2011

    in WordPress version 3.1 there is a warning message:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, class ‘post_snippets’ does not have a method ‘add_quicktag_button’ in D:\xampp\htdocs\wp01\wp-includes\plugin.php on line 395

    maybe you can solve this?
    thanx

    1. JohanFebruary 28, 2011

      Yerb,

      Thanks for the report.
      I have tried, but have not been able to reproduce the error / error message you are seeing.
      Could you provide me with some more information so I’ll be able to reproduce the error. When/where are you seeing this error? Do you have a clean wp3.1 install? Any other plugins installed?

      Cheers,
      Johan

  73. PedroFebruary 27, 2011

    I’ve been using the plugin for a while without problems. I recently upgraded to WP 3.1 and Genesys Framework 1.5.

    I have one site running v1.5.4 of the plugin without problems.

    I have another site with 1.7.1 that has some issues rendering the snippets. What happens is I will see the code below at the top of all admin pages if I have snippets created. The problem does not happen when there are no snippets. Is anyone else having the same problem? How can I fix it?

    This is what is shown at the very top of all pages:

    “; jQuery(document).ready(function($){ var $tabs = $(“#post-snippets-tabs”).tabs(); $(function() { $( “#post-snippets-dialog” ).dialog({ autoOpen: false, modal: true, dialogClass: ‘wp-dialog’, buttons: { Cancel: function() { $( this ).dialog( “close” ); }, “Insert”: function() { $( this ).dialog( “close” ); var selected = $tabs.tabs(‘option’, ‘selected’); if (selected == 0) { insert_snippet = postsnippet_0; } edInsertContent(muppCanv, insert_snippet); } }, width: 500, }); }); }); var muppCanv; function edOpenPostSnippets(myField) { muppCanv = myField; jQuery( “#post-snippets-dialog” ).dialog( “open” ); };

    Thanks,
    Pedro

    1. JohanFebruary 28, 2011

      Pedro,

      Thanks for the report.
      Do you think you could “view source” of one of your admin pages, and save the complete html code from the page and send to me? Then I can probably fix it.

      Cheers,
      Johan

  74. Tracy RottonFebruary 28, 2011

    Hi there,

    I upgraded to version 1.7.2 today, and noticed that I got a JavaScript error related to quicktabs that went away when I deactivated Post Snippets. With Post Snippets active, I also noticed obvious PHP code appearing at the very bottom of my admin dashboard, below the footer.

    I tracked down the problem to PHP being opened short-hand on line 285 of post-snippets.php, and I have that option turned off in my php.ini file. I changed the line to “<?php", and the problem was fixed.

    Hope this helps.

    – t

    1. JohanMarch 3, 2011

      Tracy,

      Thanks for the heads up. I’ve added this to the next update. :)

      Cheers,
      Johan

  75. MailBeezMarch 1, 2011

    Great plugin – just replaced global content blocks since I can use parameters in the snippets!

    Wonder if you could add the option to have surrounding tags liks

    [myShortCode title="perfect"]my content here [/myShortCode]

    this would allow to hide more complex div-stuff (e.g. for jquery-tabs).

    am also thinking of using HTMLe together with post snippets – that would allow to enrich the snippets with some code… too many ideas ;-)

    cheers
    cord

  76. MailBeezMarch 1, 2011

    ah.. just forgot:

    you mention there is an optional description field in the latest version – can’t see it but would like it!

    cord

    1. JohanMarch 3, 2011

      I just added a text area field for the description function in the settings panel. It will be available in the v1.7.3 update, released later today. :)

  77. JohanMarch 8, 2011

    I have closed the comments as the page was growing too large.
    Use the support forum at WordPress.org for questions.

    Go to Post Snippets Support Forum »