Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use WordPress text editor to behave like html

when i use text editor in WP, i have two options :

  • or i stop adding automatic <p> and <br> tags,
  • or the opposit, it gives those tags automatically.

I get crazy by that like other millions of people on the web... i would like to work as on a normal html page : when i push "enter", it gives an empty line as we see it on the screen and when we add a code, it gives a the code which behaves like a code.

Now, for example, if i do this in the text :

"this is a sample sentences <h2>here i want two words with h2 style</h2> here my sentence continues...", in the reality it gives a result like this :

<p>this is a sample sentences <br />
<h2>here i want two words with h2 style</h2><br />
here my sentence continues...</p>

I understood and i tried to remove automatisation with adding remove_filter ('the_content', 'wpautop'); to the functions file but in this case at each line break i must add a code which is crazy.

Is there a solution ???

like image 809
Igor Laszlo Avatar asked Dec 16 '13 10:12

Igor Laszlo


1 Answers

remove_filter('the_content','wpautop');

//decide when you want to apply the auto paragraph    
add_filter('the_content','my_custom_formatting_function');

function my_custom_formatting_function($content){
if(get_post_type()=='YOUR_POSTYPE_NAME') //if it does not work, you may want to pass the current post object to get_post_type
    return $content;//no autop
else
    return wpautop($content);
}

Would you please add above code in your functions.php. I hope this is helpful for you.

like image 69
Purvik Dhorajiya Avatar answered Sep 18 '22 17:09

Purvik Dhorajiya