GCB Advanced Usage Archives

Using variables within Content Blocks

You can use variables within the content block that will be replaced when the block is displayed. For example, if you create a content block, say id=1:

My name is %%name%%

by using the shortcode

when displayed it will appear as My name is John Doe.

This will be useful for developers when iterating through a list of posts or categories, for example, and will provide a reusable template.

More about shortcodes here

Using WordPress Global Variables

WordPress global variables can be used within content blocks, for example,

global $user_login;
global $user_email;
echo “$user_login, you email is: $user_email”;
would output the username and email of the current logged in user, e.g., John, your email is john@youremail.com.

More about global variables: here

Using standard WordPress shortcodes in Content Blocks

You can use standard WordPress shortcodes within a content block.

Simply add the shortcode within a block as normal, for example

to add a WordPress gallery.

Modify Content Block Output

To modify the output of content blocks you can add 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;

will convert the output to lower case.

Creating Content Blocks with PHP

You can create content blocks with PHP code.

Just copy the PHP as normal into a content block without the <?php, <?, ?> tags and insert the block into your content as normal.

Using Content Blocks in themes & widgets

You can use conent blocks outside of posts and pages. Just wrap the shortcode in the PHP function <?php echo gcb(x);?>
where x is the content block ID.

Nested Content Blocks

You can nest content blocks within content blocks by adding an existing shortcode within a new one. This can be done either using the HTML editor when creating a new content block or simply using the Insert Global Content Block function within the Visual editor to insert the existing content block within the new one.

Using the  Insert Global Content Block function you can even create a new content block while creating another one! 🙂

Content block within a content block