Global Content Blocks
Major update v1.41 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?
Then Global Content Blocks is for you!
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.4
- 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
AWESOME. I was right on the edge of learning to write plugins just to have this functionality. In answer to the question "How big a content block can I add?", there is a workaround for the 64k limit: include_once "myVeryLongFile.php"; I've used this technique successfully on the homepage of the website noted above to select the appropriate, date specific ad next to the slideshow. Well done.
Mar. 27, 2011 by william morris, Missouri
Thanks for the tip William :-)
Can I use content blocks in a widget?
Jan. 2, 2011 by Ben
Yes, by adding the following lines in your theme's functions.php file you will be able to use content blocks in a text widget:
// 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 ?>
// 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 ?>
Can it be completely uninstalled?
Dec. 26, 2010
Yes, there is an option to delete the database table if you want to completely remove the plugin.
Hi Ben -- thank you, terrific plugin! Is more documentation available than what's on this page? In particular, I'd like to know what the types 'General' and 'Code' are used for (code=js?). Thank you for any info! --Ariel
Mar. 17, 2011 by Ariel, Toronto, Canada
Hi, the types are simply to help identify the block when added to a page/post in case there are multiple blocks. It doesn't actually make any difference to the use of the plugin.
Hi Ben Really like your plugin. Do you think it would be possible to add the functionality of being able to nest blocks. i.e. create a block which has one or more shortcodes to include other [child] blocks. Does that request make sense to you? I appreciate there may be 'problems' associated with this approach i.e. a never ending loop!!! Would welcome your thoughts. Regards David
Jan. 26, 2011 by David
Hi David, interesting concept. Yes, it does make sense but because of the way GCB is designed, i.e., with each block being a self-contained shortcode as opposed to an opening and closing tag with content in between, I don't see any way that this could be done. You would probably have to create a block with your complete nested content although this would not give you the flexibility to change the contents on the fly.
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 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.
How big a content block can I add?
Dec. 22, 2010 by Ben
The content block will hold up to 64,000 characters.
How can I add the code from a Google adsense block so that it appears at the top left corner of every page or post automatically?
Jan. 17, 2011 by Kevin Foulds, London
That is beyond the scope of this plugin. There are however several excellent Adsense plugins that will do this.
I cannot get this plugin to function properly on a WP Multisite installation. I had it showing up in the visual editor at the start. I could open the plugin by clicking it's icon and was able to enter the information; name, description, and content. But it would not save the content. I exported the main sites content blogs but WP would not import them correctly into the new wp network site. Will this plugin work on WP Network Sites?
May. 3, 2011 by Steve R
Answer submitted by the poster:
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.
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.
Will I lose my content blocks if I change the theme or upgrade WordPress?
Dec. 22, 2010 by Ben
No, the blocks are added to the WordPress database so are independent of the theme and unaffected by WordPress upgrades.
Incoming search terms:
- Content Blocks
- wordpress
- wordpress cincopa
- block
- global content blocks v1 1
- tabber wordpress
- www wordpress plugin org











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
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.
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;
}