php - How to remove p tag from wordpress -


i trying remove p tag wordpress automatically adds p tag in images.also center images wordpress becomes

so tried adding code

function filter_ptags_on_images($content){ return preg_replace('/<p style=".*?">\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iu',           '\1\2\3', $content); }  add_filter('the_content', 'filter_ptags_on_images'); 

this removes style p tag , become

<p><img src=...><p> 

can me how remove p images only.

try below code:

function filter_ptags_on_images($content) {         return preg_replace('/<p>(\s*)(<img .* \/>)(\s*)<\/p>/iu', '\2', $content); } add_filter('the_content', 'filter_ptags_on_images'); 

or try modify own code:

function filter_ptags_on_images($content) {         $content = preg_replace('/<p style=".*?">\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iu',           '\1\2\3', $content);     return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iu', '\1\2\3', $content); }    add_filter('the_content', 'filter_ptags_on_images'); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -