Skip Navigation

[Resolved] Doesn't work code (action) added in the function php with custom post types

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Shane 5 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1356855

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?

#1357147

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

#1357195

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.

#1357347

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

#1357677

Yes, I can give access to the site.

#1358283

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

#1358285

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Fields

#1363835

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