0

Is there some filter to disable this, sometimes awful feature?

I need content of some custom post type to be displayed intact, with all of <br>s.

To get the content I'm using get_the_content(); inside of WP_Query loop, inside of shortcode function.

I'm grateful with any clue, but answer without the word "plugin" would blow my mind.

2
  • You can add some classname to the br tag, WP won't strip tags with classes. For example use <br class="wpse-break" >
    – bravokeyl
    Commented Jun 17, 2017 at 12:40
  • @bravokeyl yes, thanks, that is also true for attributes [data-anything]. It's odd, though, and I would really wish that I could specify: "ok WP, don't touch anything for this types of posts". Commented Jun 17, 2017 at 12:58

1 Answer 1

0

Since any attribute added to <br> tag, including class names and data-attrs keeps them from stripping, quick and incomplete way could be:

function filter_function_name( $content, $post_id ) {

  $content = str_replace('<br>', '<br data-x>',   $content);
  $content = str_replace('<br >', '<br data-x>',  $content);
  $content = str_replace('<br />', '<br data-x>', $content);
  $content = str_replace('<br/>', '<br data-x>',  $content);

  return $content;
}
add_filter( 'content_edit_pre', 'filter_function_name', 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.