Hi! I have a problem when i add a new content on my site I get tag "P" autowrapping for images and iframes (and for text but it is ok).
I have found a solution in the Internet, but it doesn't work with custom post types, just with standart post types.
Solution is adding actions (or filters) to the function.php file:
--------------------------------------
function strip_ptags_on_iframe($content){
return preg_replace('/<p>\s*(<iframe.*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
}
add_action('the_content', 'strip_ptags_on_iframe');
----------------------------------------
function filter_ptags_on_images($content){
//функция preg replace, которая убивает тег p
return preg_replace('/<p>\s*()?\s*( )\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_action('the_content', 'filter_ptags_on_images');
---------------------------------------
Result for standart sigle post - hidden link (actions works fine tags p were cut)
Result for custom post type - hidden link
Could you please help me?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Serhi,
You code is essentially to strip the p tags around the images correct?
What you can do is to use this shortcode below and it should remove the auto paragraphs.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-noautop
Please let me know if this helps.
Thanks,
Shane
Thanks Shane, I know about noautop, but in my case it doen't work
I wrapped my code - hidden link and it didn't help
Maybe do you have some guesses what I can do to force to work code from my first message? With base wordpress single posts this code works great, I don't know why it doesn't work with custom posts.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Serhii,
Your code should actually work.
Is the post being displayed by a content template? Or are the items added to a WYSIWYG custom field ?
If its on a content template there should be an option there to display the auto paragraphs.
If not would you mind allowing me to have admin access to the site to see what I can do ?
Thanks,
Shane
Yes, I can give access to the site.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Here are the private fields.
You can also send me a link to a page where I can see the issue.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Serhi,
It seems this we will need to remove this with javascript.
Given that your img tags are being wrapped with a tags then you can do this
jQuery(document).ready(function($){
$('p > a').unwrap();
});
So we are unwrapping it from the p tag.
Please let me know if this helps.
Thanks,
Shane