How to turn off automatic adding of paragraph tags

One of the things I’m running into text blocks are constantly adding <p> tags to content that I put into the source editor. This is an issue, because I’m making edits to source which will not work properly if they’re wrapped in a <p>. How do I disable this? I tried adding this to my functions.php and it did not turn it off:

remove_filter( 'the_content', 'wpautop' );
remove_filter('the_excerpt', 'wpautop');

Hello There,

Thanks for writing in. This two lines will only work if you are using the default WordPress Visual editor. Are you using Cornerstone in building your posts and pages? To avoid getting the <p> and <br> tags, please make use of the raw content element. This element will preserve anything you input in it. It will not add any html code wrapper.

Hope this helps.

That does work to do that, but now I’m limited as I don’t have all the options available (font, line-height, padding, margin, etc etc) that are available in the text block.

Are there any lines of code I can add to functions.php to disable this functionality in the text block area? I’m using the Pro theme.

Hello There,

If you want to modify the text output, you will have to override it in your child theme. You can make use of this code:

<?php

// Custom Text Output
// =============================================================================

function custom_x_shortcode_vc_text_output( $atts, $content = null ) {

  // original code
  // $output = do_shortcode( wpautop( $content ) );

  $output = do_shortcode( $content );

  return $output;

}

function remove_wpautop(){
	remove_shortcode( 'text_output');
	add_shortcode( 'text_output', 'custom_x_shortcode_vc_text_output' );	
}

add_action( 'init', 'remove_wpautop',50 );
// =============================================================================

Hope this helps. Please let us know how it goes.

I added this code to my child theme’s functions.php file. I’m still getting a <p> added to elements when I switch from HTML view to Rich Text view in a text block. I’m using the Pro theme, using a Text box (not Classic Text box). Not sure if that makes a difference or not.

Hi there,

Unfortunately, there is currently no way for getting rid of the default function where the text added through the editor gets automatically wrapped in a p tag.

However, I have added this in our feature request list so that it will be considered in the future development.

Thank you.

Okay, thank you for adding it as a request. This does create some frustrating issues.

You’re welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.