Elementor页面生成器短代码问题

8
我在使用Elementor Wordpress页面构建器时遇到了一个奇怪的问题。在创建自定义短代码并将其插入到任何页面位置后,在编辑模式下它也会出现在页面顶部。
页面顶部:

Top of the page

我想要插入短代码的位置:

place where i want to insert shortcode


function test_shortcodes() { return '短代码正在运行!'; } add_shortcode('test_shortcodes', 'test_shortcodes');我已经在Twenty Seventeen模板的function.php文件中添加了此功能。使用Elementor短代码小部件来显示我的[test_shortcodes]。它在Elementor中显示,但在实际页面上无法正常工作。 - yeshansachithak
2个回答

10

这个不相关网站上的答案帮助我解决了这个Elementor问题。https://wp-types.com/forums/topic/shortcode-output-showing-up-in-the-wrong-place/

我只需要在我的函数中包括ob_start();$content = ob_get_clean(); return $content;。以下是它的样子:

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');

0

这是我的工作示例:

  function name_it( ){
        ob_start();

        function_name();

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

只需查看 function_name();return function_name(); 行以避免错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接