I have a shortcode that is working and displaying the problem is that it jumps to the top of the page. If I have any text or other shortcodes above it in the page editor they will be displayed below this one on the front end.

add_shortcode('shortcode_exsample', 'shortcode_name');

function shortcode_name(){
return require_once ( plugin_dir_path(__FILE__) . '/shortcode_file.php');;
};

There is about 259 lines of HTML in the shortcode_file.php file that is why I am doing it this way rather that just having it inside the function.

Any idea on why this is happening would be great. Thank you.

1 Answer
1

Shortcodes are expected to return content, not echo it out. So if your shortcode_file.php file is straight html, it’s considered being echoed.

If that’s the case, you could do something like :

function shortcode_name(){
    ob_start();
    require_once ( plugin_dir_path(__FILE__) . '/shortcode_file.php');
    $content = ob_get_clean();
    return $content;
};

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *