Looking for a php function (non-jQuery or wpautop modification) approach to remove <p></p>
from within wordpress.
I tried this but it does not work:
function cleanup_shortcode_fix($content) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']',
']<br>' => ']'
);
$content = strtr($content, $array);
return $content;
}
add_filter('the_content', 'cleanup_shortcode_fix');
Try inserting this code in your
functions.php
file:add_filter('the_content', 'cleanup_shortcode_fix', 10);
I found that it works if you specify 10 as the priority; no other number will work.
This is an old question, but I solved this today and thought I’d share.
In my case, I basically want to remove all the poorly formatted
<p>
and<br>
tags, but then you want to add them back in correctly so that the text in the shortcode gets formatted correctly.This really should be the default way WordPress parses the shortcode $content parameter in my opinion.
maybe a regex could work:
That should replace any
<p></p>
with nothing or just whitespaces in it to nothing, thus removing them.When applying regex to HTML code it’s a good idea to remove the
rn
of the HTML first, since they stop the regex from working.You should increase the priority of the filter.
This should work
You can remove
Tag enter
instead of the_content()
What you need is a mix of jquery and php… that is the only working way
that i found to be working really well. i have tutorial on my site but
in order to keep stuff inhouse here goes
The jQuery:
include this in some JS file you already enqueue
A shortcode you can later use:
in your functions.php or included file
Now you can wrap specific stuff like this:
This solution requires some know how but it works!
Hope this helps…