[Plugin wpautop] Only affecting posts, not pages
-
I’m currently trying to make a child theme to twenty eleven, and so far it’s worked out well. Until i realized wordpress wraps images in p tags automatically.
My p-tags are floated right and the images left, so I can’t just remove the wpautop completely, I just want it to remove it from the images.
I found this plugin: https://gist.github.com/975026
It works wonderful on the blog post, but it makes no difference on the static pages. The code looks like this:
<?php /* Plugin Name: Image P tag remover Description: Plugin to remove p tags from around images and iframes in content outputting, after WP autop filter has added them. (oh the irony) Version: 1.1 Author: Fublo Ltd Author URI: https://blog.fublo.net/2011/05/wordpress-p-tag-removal/ */ 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... $content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); // now pass that through and do the same for iframes... return preg_replace('/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content); } // we want it to be run after the autop stuff... 10 is default. add_filter('the_content', 'filter_ptags_on_images');
Is there anyway I can alter it to make it work on my pages too? Or do anyone have a better solution?
Oh, and I have next to no experience with php, I’m only used to css/html, so I’m sorry if this is somehow a stupid question.
- The topic ‘[Plugin wpautop] Only affecting posts, not pages’ is closed to new replies.