[英]Updating failed. The response is not a valid JSON response. when add plugin shortcode
[英]wordpress add a new page or update cause The response is not a valid JSON response because of simple plugin
我正在尝试在 WordPress 中制作一个插件。 该插件工作正常,但是当有人添加新页面或更新页面时,它会显示一条错误消息:
The response is not a valid JSON response.
我检查了插件代码,发现它这样做是因为文件中的 html 部分代码。 我试图找到解决办法,但到目前为止还没有运气。
这是PHP插件文件,你能告诉我哪里错了吗
<?php
/*
* Plugin Name: test
*/
function testfunc () {
?>
<div class="testcl">test</div>
<?php
}
add_shortcode('test','testfunc');
?>
我认为您在创建简码时需要缓冲 output 模板。 试试这个代码:
<?php
/*
* Plugin Name: test
*/
function testfunc () {
ob_start();
?>
<div class="testcl">test</div>
<?php
return ob_get_clean();
}
add_shortcode('test','testfunc');
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.