Remove P tags with multiedit plugin

147 Views Asked by At

I'm using the multiEdit plugin to create some content regions on a template.

One of those region is for some photos that are going to be using jQuery cycle to rotate through the images.

But, as usual, Wordpress (or the editor rather) is wrapping all of the images in a <p> tag.

I've used the functions hack from CSS-Tricks to remove the <p> tags from the content:

function filter_ptags_on_images($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');

But, from what I can tell, it only looks for the_content and not for anything else.

Multiedit uses this: <?php multieditDisplay('name_of_region'); ?> to display the content block in the template.

So, I tried to change the function to this:

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

But no such luck.

So, I'm not so sure if I'm missing something or just going about it the wrong way.

2

There are 2 best solutions below

0
On

Ok, well I found a workaround.

I did a write up about it here:

http://ultraloveninja.roon.io/filtering-paragraph-tags-with-the-wordpress-multiedit-plugin

0
On

Instead of placing multiEdit fields in your template like this example

<?php multieditDisplay('Top'); ?>

You could prevent the auto print by passing true as the second parameter like this

<?php echo multieditDisplay('Top', true); ?>

So if you want to strip ALL tags from the output, then try this

<?php echo strip_tags(multieditDisplay('Top', true)); ?>

If you want to include certain tags then provide a list of tags to include and pass it as a parameter to strip_tags like this

<?php echo strip_tags(multieditDisplay('Top', true), '<p><a>'); ?>