我正在使用Black Studio TinyMCE Widget 作为富文本编辑器小部件。在侧栏中,我插入了带有[testimonial]
短代码及其后的一些内容。
例如:
[testimonial]
Read more client testimonials (as a link)
当我切换到该小部件的HTML选项卡时,我得到了以下内容:<p>[testimonial]</p>
<p><a title="Testimonials" href="http://mm.dev/testimonials/">Read more client testimonials</a></p>
shorcode仅显示随机Testimonial
CPT职位:add_shortcode("testimonial", "dlma_testimonial_shortcode");
function dlma_testimonial_shortcode($atts, $content = null){
$args = array(
\'post_type\' => \'testimonial\',
\'post_status\' => \'publish\',
\'posts_per_page\' => \'1\',
\'orderby\' => \'rand\'
);
$testimonial = new WP_Query($args);
if($testimonial){
return apply_filters(\'the_content\', $testimonial->posts[0]->post_content);
}
return "";
}
但是,当我查看页面时<p>
插入元素:Edited thanks to Tom J Nowell
<div class="textwidget">
<p>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum velit convallis sem pulvinar vitae lobortis metus varius.” <em>Person name, Person job</em></p>
</blockquote>
</p>
<p>
<a href="http://mysite.com/testimonials/" title="Testimonials">Read more client testimonials</a>
</p>
</div>
The[testimonial]
然而,shortcode得到了正确的扩展,因为它最初被包装到<p>
小部件中的元素,它似乎仍被包装在其中。我已尝试删除<p>
但是,只要单击Save按钮<p>
元素再次插入。我试着移除不需要的<p>
元素,该元素用the_content
过滤如下:
remove_filter( \'the_content\', \'wpautop\' );
add_filter( \'the_content\', \'wpautop\' , 12);
那没用。我猜我在处理带有短代码的小部件的内容时出错了。我现在很困惑。如何删除不需要的<p>
包裹短代码的元素?我将非常感谢任何帮助!
非常感谢。