Skip Navigation

[Resolved] Prevent p tag in WYSIWYG editor

This support ticket is created 6 years, 4 months 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by th 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#1108096

th

I am trying to prevent WordPress from automatically adding the <p> tag in WYSIWYG editor.

For the default post content area, I can use the code

<?php remove_filter ('the_content', 'wpautop'); ?>

But if it's a WYSIWYG editor custom field created by Toolset, then what code should I use? I want this applied to all WYSIWYG editor custom field created by Toolset.

#1108214

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

When you insert a WYSIWYG field using the Fields and Views button there is an option to allow third-party filters or not.

If you choose not, it will insert the shortcode like so:

[types field='whizzy' suppress_filters='true'][/types]

That suppresses the p tags, too.

#1108788

th

Thanks for the reply. I have inserted

suppress_filters='true'

inside the toolset WYSIWYG custom field on a View and Content Template edit page.
However, it still automatically added <p> tag upon save/publish of a post.
I changed the singular quotation mark to double, and I also cleared cache on the browser and server.
You said it 's an option to allow or not allow third-party filters, but it seems to be a built-in native WordPress feature to add an automatic <p> tag, not the doing of other third-party plugins.
Maybe is there a way to code inside functions.php that might work better? Or have I missed something?

#1108809

th

I'm not entirely sure but the following code in functions.php seems to work fine.

add_filter( 'the_content', 'disable_wpautop_cpt', 0 );
function disable_wpautop_cpt( $content ) {
	'custom-post-type' === get_post_type() && remove_filter( 'the_content', 'wpautop' );  
	return $content;
}

When I edit inside the text editor, upon publish the post automatically wraps <p> inside the text editor.

However, when I check the frontend of the website, it seems <p>'s attributes are not in effect, even though they are being 'printed,' both in the content area of the post, as well as the WYIWYG custom field created by Toolset.

This is not the perfect solution yet, so should someone else find a better solution, I'd appreciate you let me know!