9

I'm facing a weird problem when using the Elementor Wordpress Page Builder.

After creating a custom shortcode and inserting it into any page position, it also shows up at the top of the page, but only in Edit mode.

Top of the page:

Top of the page

Place where I want to insert shortcode:

place where i want to insert shortcode

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Fahem Ahmed
  • 91
  • 2
  • 6
  • `function test_shortcodes() { return 'Shortcodes are working!'; } add_shortcode('test_shortcodes', 'test_shortcodes');` I have added this function in Twenty Seventeen template `function.php` file. Use Elementor shortcode widget to display my `[test_shortcodes]`. It shows in elementor but not working on live page. – yeshansachithak Oct 19 '17 at 09:33

2 Answers2

10

This answer on an unrelated site helped me solve this Elementor issue. https://wp-types.com/forums/topic/shortcode-output-showing-up-in-the-wrong-place/

I just had to include ob_start(); and $content = ob_get_clean(); return $content; in my function. Here is what it looks like:

function custom_author_link_function() {
        ob_start();

        coauthors_posts_links();

        $content = ob_get_clean();
        return $content;
}
add_shortcode('custom_author_link', 'custom_author_link_function');
Colin Oakes
  • 354
  • 4
  • 7
0

This is my working example:

  function name_it( ){
        ob_start();

        function_name();

        $content = ob_get_clean();
        return $content;
   return function_name();
}
add_shortcode( 'shortcode_name', 'name_it' );

Just look at function_name(); and return function_name(); lines to avoid errors.