I have a shortcode inside a plugin I wrote. The shortcode always prints on top, after a bit of research I found that I have to 'return' instead of 'echo' for me to get it in the right place.
我在我写的插件中有一个短代码。短代码总是打印在顶部,经过一些研究后我发现我必须“返回”而不是“回声”让我把它放到正确的位置。
I have inline HTML , css , javascript in various script tags inside the PHP file. Is there a way I can get it work without trying to return all the inline HTML. (adding 'return' to all html tags is a huge endeavour) ?
我在PHP文件中的各种脚本标签中都有内联HTML,css,javascript。有没有办法我可以让它工作而不试图返回所有内联HTML。 (在所有html标签中添加'return'是一项巨大的努力)?
I know that a question on shortcode printing on top has been asked but this is not entirely the same problem I am having.
我知道有一个关于短代码打印的问题已被问到,但这与我遇到的问题并不完全相同。
Appreciate your answers.
感谢您的回答。
Just for people to get an idea of the code I am dealing with: This is just a small chunk of the code, but there is html, css spread all over the place.
只是让人们了解我正在处理的代码:这只是代码的一小部分,但有html,css遍布各处。
extract(shortcode_atts(array(
'id'=>'0', 'key'=>'0'), $atts));
if(substr($id, -3) == "***") $id = substr($id, 0, 8);
$id_licenses = getDbInfo($id);
$id_desc = array();
if(is_array($id_licenses)) $id_desc = $id_licenses;
else $id_desc[0] = $id_licenses;
if(isset($_POST['desc'])) {
$info = $_POST['desc'];
$ids = getDbInfoByDesc($info);
}
?>
<style type="text/css">
label.inputlabel
{
width: 8em;
float: left;
text-align: left;
margin-right: 0.5em;
display: block;
padding-left: 0.5em;
font-family: Tahoma;
}
1 个解决方案
#1
5
You have to return the final result but if you want you can buffer the result and echo
anything inside the buffer then can retun the buffered data, i.e.
您必须返回最终结果,但如果您需要,您可以缓冲结果并回显缓冲区内的任何内容,然后可以重新调整缓冲的数据,即
function yourShortCodeFunction(){
ob_start();
echo "Hello"; // this will not print out
// more code
$result = ob_get_contents(); // get everything in to $result variable
ob_end_clean();
return $result;
}
#1
5
You have to return the final result but if you want you can buffer the result and echo
anything inside the buffer then can retun the buffered data, i.e.
您必须返回最终结果,但如果您需要,您可以缓冲结果并回显缓冲区内的任何内容,然后可以重新调整缓冲的数据,即
function yourShortCodeFunction(){
ob_start();
echo "Hello"; // this will not print out
// more code
$result = ob_get_contents(); // get everything in to $result variable
ob_end_clean();
return $result;
}