PHP 阻止WordPress在段落标记中包装图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 阻止WordPress在段落标记中包装图像相关的知识,希望对你有一定的参考价值。

// stop wordpress from wrapping images in <p> tags
	function filter_ptags_on_images($content)
	{
		// do a regular expression replace...
		// find all p tags that have just
		// <p>maybe some white space<img all stuff up to /> then maybe whitespace </p>
		// replace it with just the image tag...
		return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
	}
	
	// we want it to be run after the autop stuff... 10 is default.
	add_filter('the_content', 'filter_ptags_on_images');

以上是关于PHP 阻止WordPress在段落标记中包装图像的主要内容,如果未能解决你的问题,请参考以下文章