Global Content Blocks
Major update v1.5 released – click here to see summary of new features
As featured on ManageWP (see review/tutorial)
- Do you use the same code snippets in multiple pages and posts?
- Do you add forms, opt-in boxes, Adsense code and other HTML to your content?
- Are you fed up with the WordPress editor stripping out your code, changing your formatting or adding in extra line breaks?
A solution so simple it’s amazing that it hasn’t been done before!
Global Content Blocks allow you create your own shortcodes to add code snippets or HTML including forms, optin boxes, iframes, Adsense code, etc, to pages and posts. They are ideal for inserting reusable objects or to prevent the WordPress editor from stripping out your code or otherwise changing your formatting. Please let me know of any other uses you find for it by adding a comment below.
Here’s how easy it is to use Global Content Blocks…
Summary of new features in Global Content Blocks v1.5
- Added visual editor when creating content blocks
- Can now use variables within content blocks
- Added ability to insert PHP blocks into content
- Option to insert to entire content block into pages/posts instead of the shortcode
- Option to select the block type, each represented by a different image block when inserted into content making it easier to identifyon the page
- Added export function to export all or selected content blocks to an xml file that can be imported into the Global Content Blocks plugin on another WordPres site
- Added a link to the Settings page from the Plugins page listing
- Added hook to run scripts in functions.php file on output
- Shortcode to use Content Blocks in widgets and non-post/page content
// use Global Content Blocks in widgets
add_filter( ‘widget_text’, ‘shortcode_unautop’);
add_filter( ‘widget_text’, ‘do_shortcode’);
Just add them at the end of the file before the closing ?>
I don’t think it’s what you’re trying to achieve but you can create a block with a number of stacked shortcodes, e.g.,
[contentblock id=8]
[contentblock id=9]
[contentblock id=10]
and if this block is inserted into a page/post using the ‘Insert full content’ option, the individual blocks will all be displayed.
I figured this problem out on how to make your plugin work reliably with WordPress Multisite.
1)Install the Unfiltered HTML Plugin from Wordpress. After installing in Multisite and activate.
2)Create a mu-plugins directory in the wp-content folder
3)Move the unfilted-mu folder from wp-content/pluigins to wp-content/mu-plugins
4)From the Network admin Plugins screen use network reactivate 5)As Network Admin go to the networked site and use Global Contents Block as normal.
When I built my content blocks I chose Code and copied my iframe data into the content area and save the content. From the visual editor I would select the content block to insert and it worked fine.
This worked for me twice and has not been tested thoroughly but I do have your plugin working reliably on one networked site.
Incoming search terms:
- Content Blocks
- wordpress
- WPXpert
- wpxpert com
- powered by SMF william morris











Wow, I was just getting frustrated last night about cutting and pasting code snippets off Notepad into pages, and wishing there was a way to add buttons or shortcode for anything I wanted. This is awesome. Now it would be a lot MORE awesome if I could bundle up all those code snippets I entered and transport them to another site.
That’s also a good idea Jon. If you know your way around phpMyAdmin you could do it by exporting the contents of the gcb table direct from the database and import it into another site’s database but definitely another suggestion to add to the list.
Thanks and Happy New Year,
Ben
Just to let you know that an Import/Export feature has been included in Global Content Blocks v1.1 that has just been released. Will let you export as an xml file from the Settings page and import into the plugin on another site.
I love the idea of this plugin and the interface is great! In my particular case, I write a column that has a lot of frequently used hotel, club and show names with links. Although the plugin works great for this, having a file with dozens of “Global Content Blocks” can get really confusing (I tried it). I’d like to suggest an option that would simply allow me to insert a block of actual code without the shortcodes. In my case, I don’t have problems with the editor sttipping out these simple HTML codes. Thanks for your consideration!
Thanks for the suggestion Bryan. The next version of the plugin will insert a different label image in the content depending on the content type but doesn’t sound like this will help you if all the blocks are the same content type. We’re also trying to find a way to insert the name of block in the label to make it easier to know what each block is so that may be of more use to you.
I do however like your idea. The primary purpose of the plugin is to insert the code blocks as shortcodes but it should be possible to offer an option to insert via shortcode or to insert the actual content of the block. Will add it to my list!
Thanks again for the suggestion and Happy New Year.
Ben
Just to let you know that the feature you suggested has been included in Global Content Blocks v1.1 that has just been released. When you insert the block into your page/post using the icon on the editor toolbar it has an option to insert the full block instead of the shortcode.
Excellent idea – I think one of the best plugin ideas and realizations in 2010. I used to write custom code for my short-codes. This really brilliant. And the integration into the editor is the icing on the cake.
Thanks Tom, glad you like it.
Feel free to give the plugin a rating at http://wordpress.org/extend/plugins/global-content-blocks
Is there a way to add in php code for this plugin so I can run these block through a template and keep any consistent code nice and secure away from wysiwyg or text widgets? Beautiful plugin and seems nice and slim.
That’s something that is on my list but in the meantime, try using Global Content Blocks along with the Exec-PHP plugin. In theory it should work. Please let me know if it does.
Ben
Just to let you know that the ability to use the plugin with PHP blocks has been included in Global Content Blocks v1.1 that has just been released. You can now include PHP code (without the PHP tags) as you would any other type of block and insert in your post/page.
Brilliant! I will check it out, very impressive Ben.
Many thanks,
-Kevin
Excellent plugin. Just one question about the PHP function: will this be enabled for all users when the plugin is activated? Or can it be switched off for everybody below Super Admin(on a WP multisite)? This to prevent obvious security risks.. Thanks!
The plugin was not written with multisite in mind so no, this functionality has not been included. Sorry
great plugin! I found an issue – the tinymce button breaks other plugin’s buttons. I’m using the EG-Attachments plugin and WP eCommerce and both their tinymce buttons disappears when Global Content Blocks is activated. Any idea why that’s happening?
Thanks for letting me know. Will check it out and release a fix shortly.
First of all, thank you for this plugin. It really helps! ^^
But i want to know why it doesn’t work in the excerpts?
Excerpts do not handle text the same way that pages and posts do. The plugin was designed to work with pages and posts only.
Hi Ben
Query about export and xml. I have tested export and import and work fine. Really useful functionality.
However, the export file is of gcb extension and not editable – is it possible to have the export file as xml extension and editable?
We might look at converting the import/export function to xml but as the blocks can be edited after they’ve been imported it is not a priority at the moment.
Hi Ben
Understand your comments re: xml files.
One further feature request: The ability to reference the block by either id or name.
So instead of id=… we can put name=… in the shortcode. I fully understand the issues to do with duplicate names etc – but this functionality we would be very helpful within my applications.
Not really sure why this would be needed as when inserted via the drop down list in the editor window you can see the name of the block?
i was unable to submit my question through the FAQ thing — kept getting an error
is it possible to mix html and php?
i know very little about php, but this is what i’m trying to do…
Read Me File
so the first part is a css class to collapse the content until the user clicks the expand link
the second part is the php which i want to include the contents of the ReadMe file
Please see http://wordpress.org/support/topic/plugin-global-content-blocks-js-and-php-in-one-block
Hey! I REALLY love this plugin! It’s something I have been missing for a long time!
Only one little thing bugs me…
I wish there was a TinyMCE-Editor for regular content. So it would be easier to edit.
Right now I use the regular page editor to generate the code and then paste it into the content block content field.
But anyways! It’s great!!!
FYI, version 1.5 includes a visual editor.
Love this plugin! Thanks so much for creating this.
One feature I’d love to see would be the ability to create content blocks using the WYSIWYG editor. That way clients without HTML coding knowledge could easily create/update blocks of code.
Keep up the great work.
Version 1.5 has just been uploaded to the repository and includes a visual editor.
You can?t use TEXTAREA in forms.
After using it in add block editor ? the rest of the form stays uneditable.
(Content field cuts the code just before TEXTAREA closing tag.)
Could you please repair it?
This has been fixed in the latest version.
Would it be possible to add the tinymce functionality to this plugin?
Brilliant!
It’s a good alternative for getting custom field values, for some applications.
Is there any limit to how many content blocks can be handled, either at the admin page, TinyMCE or when the final page is created? I have a potential application that could use a large number.
No, there is no limit to the number of blocks that can be added (other than phusical size of the database).
Love the plugin.. one feature I am missing.. a way to pass a paramter to the block..
Let’s say my block contains the text: “Name:[name]”
It would be nice if I could call it with [contentblock id=1 name=alex]
And the output would be: Name:Alex
Do you know of any plugin that can do this?
Is this what you mean, (taken from the FAQ at http://wordpress.org/extend/plugins/global-content-blocks/faq/)
Is it possible to modify the output of inserted content blocks?
Yes, you can add the filter ‘gcb_block_output’ to modify output by adding a PHP script to functions.php, for example:
add_filter(‘gcb_block_output’, ‘alter_block_output’);
function alter_block_output($value) {
//process the output here, e.g., convert text to lowercase
$new_value = strtolower($value);
return “Processed output: “.$new_value;
}
Hi! Your plugin seems like an interesting option to give a client the oportunity to include custom snippets. I’d rather prefer add custom code to a new template page, and then use that page as my custom design.
However there is an interesting approach about params I think is not covered by the FAQ quote you has taken. At least to the degree I can understand, since I don’t want to change the *output* after the script has run, instead, I want to change the way the scripts behaves based on certain params.
In example, I’d easily (or not so… bear with me) could make a script to loop over the last posts in certain category, then format the resultset to a slideshow (no matter the technique about this), and that way use some your GCB to show more than one featured posts slideshow in a custom page. But trying to “reuse” that code to build a block for another Category, rapidly evolves into a mess, since we just can copy-and-paste changing the category we want to in the other block. And even if I can easily point the bit of text I need to change in every script, that is not an option to most clients.
So, if your shortcode could accept params, it could just a matter to craft the script to accept a category parameter. It then could be adapted to almost any need for quick custom code.
Anyway, thank you very much for your plugin, I’ll test it with my team.
Thanks for the suggestion. Sounds like a good idea, I’ll go ahead and add it to the plugin and do an update on the repository, hopefully in the next few days.
Ben
FYI, version 1.5 has just been uploaded to the repository and includesthis feature. See http://wpxpert.com/category/gcb-advanced-usage/ for advanced usage instructions.
I see what you mean now. This feature has been included in the new version 1.5. See http://wpxpert.com/category/gcb-advanced-usage/ for advanced usage instructions.
Hoping for Multisite/WP Network compatibility. This plugin is a life saver on WP sites!
I don’t use Multisite so have not tested it but I don’t see why it wouldn’t work. Have you tried it?
Awesome update Ben!
I know I’m late to the party but this is an AWESOME plugin!! I’ve been looking for something JUST like this for a few hours – I desperately needed something that would add the code rather than the shortcode…perfect for creating pre-styled tables as columned sections for clients to insert and then visually modify! Great job!!! (=^_^=)
Hi Ben
Been using your Global Content Block plugin for a while, it is one of the most useful WP plugin I think. I want to use it on WP Multisite installation but not sure of it can be used in the way I want; basically I want to create a global block of content in one blog (say blog 1) then use that global content across blog 2, blog 3, blog 4, etc. is this possible?
The export/import is pretty useful and I could use that option but the ability to use a block across an entire network would so awsome.
best regards
Glad you like the plugin Lee. I’m not very faliliar with multisite and don’t use it myself so haven’t tested the plugin with it. I think it’s unlikely that it will do what you ask but give it a try and let me know what happens…
Ben
Great Plugin. Exactly what I was looking for.
Is it possible to change the contentblock ID from a number to a custom ID, such as a string of letters and numbers?
So, rather than [contentblock id=1] the user could enter a custom string so that it reads [contentblock id=customstring123]
Hi Jeremy, it doesn’t do that at the moment but I can see the value of being able to customise shortcodes. Will add it to the list for a future release.
Ben
FYI Version 1.5 has been uploaded to the repository and includes a visual editor.