为什么我的简码比其他内容先执行? [英] Why does my shortcode get executed before other content?

查看:53
本文介绍了为什么我的简码比其他内容先执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面中有以下文字.如您所见,我的简码位于底部,但是以某种方式在代码运行时,我的简码的输出将插入页面的顶部,而不是跟随其先前的内容.

I have the following text in a page. As you can see my shortcode is right at the bottom but somehow when the code runs, the output of my shortcode is inserted at the top of the page instead of following its preceding content.

<img class="alignnone" title="title_enquires" src="http://localhost/barcelona/wp-content/uploads/2011/08/title_enquires.jpg" alt="" width="589" height="77" />
<img class="alignnone" title="contact_map" src="http://localhost/barcelona/wp-content/uploads/2011/08/contact_map.jpg" alt="" width="555" height="222" />

[barcelona_address]

这是我在function.php文件中的简短代码注册:

Here is my short code registration inside the function.php file:

<?php
add_shortcode( 'barcelona_address', 'barcelona_shortcode_handler' );

function barcelona_address_func()
{
    print "<p>sdsdsds</p>";
}

function barcelona_shortcode_handler( $atts, $content=null, $code="" ) 
{
   if (function_exists($code . "_func"))
   {
       call_user_func($code . "_func", $atts);
   }
}
?>

结果是:

<p>sdsdsds</p>
<img class="alignnone" title="title_enquires" src="http://localhost/barcelona/wp-content/uploads/2011/08/title_enquires.jpg" alt="" width="589" height="77" />
<img class="alignnone" title="contact_map" src="http://localhost/barcelona/wp-content/uploads/2011/08/contact_map.jpg" alt="" width="555" height="222" />

推荐答案

您的简码处理程序应该返回输出以代替简码显示,而不输出任何本身.

Your shortcode handler is supposed to return the output to display in place of the shortcode, not output anything itself.

http://codex.wordpress.org/Shortcode_API

这篇关于为什么我的简码比其他内容先执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆