Library layout inside the Divi post content module

If you’re using a Theme Builder template for your single posts, then you’re using the ‘post content’ module to grab the content of your posts, and display and style it as defined in that Theme Builder template.

Great! This is why we love the Theme Builder. But…

What if you want to add a module inside that content, like a call to action? Not before or after, but inside the content, where it’s actually relevant to whatever the post is talking about?

Technically you can’t. All your post content is displayed within the dynamic post content module.

You can of course, switch to using the Divi builder on your posts instead of a Theme Builder template, but that defeats the object. Plus, let’s say you’ve got 50 existing posts. Editing everyone of those to use the Divi builder ‘on page’ is a pain in the arse.

But there is a solution. You’re going to have to do a little work if you already have a load of posts, but it’s a whole lot less work and you don’t have to lose the beautiful Theme Builder template you worked so hard on.

Yes, of course I’m going to show you how ?

Use a child theme.

We need to add a PHP function to create a shortcode that we can then use to define which library layout to show in our post content.

Here is the code you need to copy and paste into your child theme functions.php file.

function showlibraryitem_shortcode($moduleid) {
extract(shortcode_atts(array('id' =>'*'),$moduleid)); 
return do_shortcode('[[et_pb_section global_module="'.$id.'"][/et_pb_section]]');
}
add_shortcode('showlibraryitem', 'showlibraryitem_shortcode');

‘showlibraryitem’ is how we will call this function in the post content.

Once you’ve added that code to your child theme functions PHP file, create whatever section, row, or module you want to display inside your post content and save it to your Divi Library. Then grab the ID for that layout and make a note of it.

How? Just hover over the library layout and check the post ID that appears at the bottom of your browser window. You also see this number (red box) in the address bar if you’re editing the layout inside the library.

Custom content inside divi post content module

Adding the shortcode.

Now open up the post you want to add your library layout to, and in the text editor enter your shortcode with the ID of the library layout you just created.

[showlibraryitem id="12345"]

Publish your post, and voilà!

That’s it, all done!

Michelle x

Pro Pass Membership

Want access to all current and future child themes, kits, and our B&B Blocks library for Kadence for one low annual price?

Brand & Build Pro Pass

Latest

In the shop

  • Kadence
    Lane Wordpress Theme for KadenceLane Wordpress Theme for Kadence

    for content creators

    £175.00

    View Details 🡢

  • Kadence
    Liora Child Theme for KadenceLiora Child Theme for Kadence

    for bloggers

    £175.00

    View Details 🡢