这个不相关网站上的答案帮助我解决了这个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');
这是我的工作示例:
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(); 行以避免错误。
function test_shortcodes() { return '短代码正在运行!'; } add_shortcode('test_shortcodes', 'test_shortcodes');
我已经在Twenty Seventeen模板的function.php
文件中添加了此功能。使用Elementor短代码小部件来显示我的[test_shortcodes]
。它在Elementor中显示,但在实际页面上无法正常工作。 - yeshansachithak