自定义短代码始终显示在页面顶部

时间:2017-05-03 15:52:11

标签: php wordpress

我在这里意识到存在类似的问题,但是所有代码都包含了不同的代码。我在functions.php文件中配置了自定义短代码,由于某种原因,它始终显示在页面顶部。我所做的一切似乎都无法移动它。这是代码中某些内容的结果吗?

function menu_shortcode( $atts ) {
     return wp_nav_menu( array( 'theme_location' => 'header' ) );
}
add_shortcode( 'nav', 'menu_shortcode' );

2 个答案:

答案 0 :(得分:1)

好的,我已经在我自己的WordPress安装上使用以下代码对其进行了测试:

function menu_shortcode() {
     return wp_nav_menu( array( 'theme_location' => 'header' ) );
}
add_shortcode( 'b3_add_menu', 'menu_shortcode' );

我创建了一个名为test的页面,并为其添加了短代码[b3_add_menu]。这是结果:

Test

对我而言,菜单不会仅显示在页面顶部,您是否可以告诉我您在哪里放置了" nav"短码?

答案 1 :(得分:1)

您的短代码正在返回<form> <fieldset class="display"> <output name="output" id="output" class="output"></output> <output name="input" id="input" class="input"></output> </fieldset> <fieldset class="keys"> <button type="button" name="key-0" id="key-0" class="number" value="0">0</button> <button type="button" name="key-1" id="key-1" class="number" value="1">1</button> <button type="button" name="key-2" id="key-2" class="number" value="2">2</button> <button type="button" name="key-+" id="key-+" value="+" class="operator">&plus;</button> <button type="button" name="key-3" id="key-3" class="number" value="3">3</button> <button type="button" name="key-4" id="key-4" class="number" value="4">4</button> <button type="button" name="key-5" id="key-5" class="number" value="5">5</button> <button type="button" name="key--" id="key--" value="-" class="operator">&minus;</button> <button type="button" name="key-6" id="key-6" class="number" value="6">6</button> <button type="button" name="key-7" id="key-7" class="number" value="7">7</button> <button type="button" name="key-8" id="key-8" class="number" value="8">8</button> <button type="button" name="key-*" id="key-*" value="*" class="operator">&lowast;</button> <button type="button" name="key-9" id="key-9" class="number" value="9">9</button> <button type="button" name="key-c" id="key-c" class="command">C</button> <button type="button" name="key-=" id="key-=" class="command">&equals;</button> <button type="button" name="key-/" id="key-/" value="/" class="operator">&divide;</button> </fieldset> </form> ,但该功能默认输出。不允许使用短代码生成输出,因此您需要将echo设置为false以防止它出现。

wp_nav_menu()

文档:

您收到的原始问题的答案已更新,以解决您所描述的问题:How to make a PHP function into a short code

相关问题