wordpress短代码格式化问题

时间:2012-05-24 07:01:09

标签: wordpress shortcode

我为wordpress插件创建了一个短代码,并在wordpress的页面内容中的两个句子之间放置了短代码。但这两个句子显示在pugin部分的底部。可能是问题吗?

我将短代码设为,

我的插件

[插件]

新的wordpress插件......

但插件中的Html内容显示在顶部。然后“我的插件”和“新的wordpress插件......”部分位于底部。我在“我的插件”和短代码之间尝试了“br”标签。但是“我的插件”总是显示在短代码部分下。没有在HTML代码和css中找到的错误。请帮助我。

1 个答案:

答案 0 :(得分:1)

我假设您在短代码中使用过echo。

永远不要在你的

中使用echo“Blah Blha”

前:

糟糕的方式

function headbox() {
if (is_home()) {
    echo '<div id="headbox">';
    echo '<h1>Test</h1>';
    echo '</div>';
    }
}
add_action('thesis_hook_header', 'headbox');

使用return的正确方法

function headbox() {
if (is_home()) {
    $foo = '<div id="headbox">';
    $foo .= '<h1>Test</h1>';
    $foo .= '</div>';
        return $foo;
    }
}
add_action('thesis_hook_header', 'headbox');
相关问题