Question

I have functional php code for a page which creates a table. To get the table to display on the front end, I used a Page Template (see code) to create the page (in Page Attributes), rather than using the default template.

I would now like to add a Divi text module at the top of the table that the user sees. I've got a "Hello World" prototype working but am struggling to incorporate it into my Table page. Any ideas? Snippet:

/**
 * Template Name: MyTable
 *
 * @package WordPress
 * @subpackage TNG 
 */
<div id="main-content" class="main-content">

//
//some code here
//

<div class="entry-content">
<?php

//use 'the_content()' to display php content on the WordPress page

    the_content();

?>
</div> <!-- .entry-content -->
<?php echo "<h2>Hello World</h2>"; ?>
Was it helpful?

Solution

If you are using DiviBuilder and you need to inject some custom php code to be run, and render inside divi generated block. You can create your custom shortcode and use it inserting into divi's wysiwyg blocks.
Shortcodes are custom tag like structures but use [] instead of <> as in html - their mission is to execute your custom php code to generate html or perform some other actions on page. In both cases function which renders shortcode returns string of html, so shortcode gets replaced in result page with it's generated html.

This code below can be placed in your theme's functions.php or as a plugin.

function your_shortcode_renderer($atts=array(), $content=''){

// below are different return just to demonstrate approaches of shortcode creation - use one return for your shortcode.
   return '<h2>Hello World</h2>'; // example of static or dynamic something rendered.
   return '<h2>' . $content . '</h2>'; // example of utilizing wrapped shortcode's content.
   // sure you can pass in some variables as shortcode attributes and they will be in $atts associative array.
}
add_shortcode('your_custom_shortcode', 'your_shortcode_renderer');

So in Divi builder's wysiwyg, or inside wordpress page's content you can then place your shortcode like this:

[your_custom_shortcode] - just to render shortcode generated content, or

[your_custom_shortcode some="atribute_value"] if you need to pass in some values, or

[your_custom_shortcode] Some inner content [/your_custom_shortcode] - to utilize shortcode's wrapping some content feature, so you can use this wrapped content inside shortcode renderer.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top