Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Elementor page builder shortcode issue – unable to include external PHP file when using ob_start and ob_get_clean

I have a weird problem when I try to include my custom wordpress plugin shortcode within elementor. Whenever I use an external php file there is no output.

This code is working fine:

// Shortcode Output function
function vergleichsplugin_output_frontend() 
{

        ob_start();

        echo '<div class="vergleichsplugin"></div>';

        return ob_get_clean();

}


/* Shortcodes */ 
add_shortcode('vergleichsplugin','vergleichsplugin_output_frontend'); 

But this doesn’t produce any output at all (file path is correct):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

// Shortcode Output function
function vergleichsplugin_output_frontend() 
{

    ob_start();


    $html = require_once(ABSPATH.'/wp-content/plugins/vergleichsplugin/views/frontend/frontend.php'); 


    $html = $html.ob_get_clean();
    return $html;
}



/* Shortcodes */ 
add_shortcode('vergleichsplugin','vergleichsplugin_output_frontend'); 

content of frontend.php is the same:

echo '<p>Output</p>'; 

>Solution :

Have you tried something like this?

function vergleichsplugin_output_frontend() {
    ob_start();

    include(ABSPATH.'/wp-content/plugins/vergleichsplugin/views/frontend/frontend.php'); 

    return ob_get_clean();
}
add_shortcode('vergleichsplugin','vergleichsplugin_output_frontend'); 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading