WordPress paragraph autoformat
The objective of this article is to understand the autoformat that WordPress gives to the paragraphs (in the line breaks) so that we can decide if we really need to deactivate them or not.
I must make it clear from the beginning that all the examples are done working in the Visual WordPress editor since in the Text editor the automatic format changes.
I must start by saying that the function of the WordPress core responsible for making paragraph autoformat is wpautop and its objective is to replace the line breaks with the corresponding HTML tags to generate a valid XHTML code.
The main problem that users encounter with WordPress paragraph autoformat is that sometimes the result gives a very large spacing, just as other times we do not get a very small or non-existent paragraph spacing.
Well, in this article we will try to understand the operation of this
wpautop function in
wpautop to handle it correctly and be able to predict how the result will be after the application of autoformat and that it fits our needs.
Let’s start with an example writing in the Wordpres visual editor:
Esta es la primera línea y ahora pulso Intro. Esta es la segunda línea y ahora pulso Intro. Esta es la tercera línea y ahora pulso Intro.
And now we can see the result in the image:
HTML code result:
As we can see every time I press the key to the
Intro , I will add a paragraph enclosed by the HTML tags
<p> </p> , so the spacing between paragraphs will depend on the CSS code of our template.
The question is when I need to make a line break, but I want to stay within the same paragraph. In other words, when I want to make a line break but keep writing within the same block of HTML tags
<p> </p> . This is achieved by pressing the key combination
Shift + Intro . With this I get that for the line breaks I use the HTML tag
<br> staying within the original paragraph.
How we can see the spacing between lines is smaller, and there is a single paragraph enclosed between the HTML
<p> </p> tags.
Another important thing is when we try to bend the line breaks to get more spacing, we must use them carefully, so I show you how they work. When at the end of a line we make two consecutive line breaks by pressing the
Intro key twice, what we get is to add a blank paragraph between each line, that is, the blank paragraph will only contain the HTML tags
<p> </p> .
When we press the Shift + Intro combination twice at the end of a line, we do not get a greater spacing since WordPress that double
Shift + Intro treats it just like a line break made with an
Intro press. When treating it just as if we press the
Intro key, it will enclose each line in a separate paragraph with their respective HTML tags
<p> </p> .
We can see in the images that the distance between lines is greater, since it adds a blank paragraph between each line. Keep in mind that this space will be more or less depending on the margins that your template applies in the CSS to the HTML
How to disable WordPress autoformat.
To deactivate the automatic format we have two options:
- Disable the wpautop function from the functions.php file by adding the code:
//Eliminar párrafos automáticos por defecto remove_filter('the_content', 'wpautop');
- Use the Disable wpautop plugin that allows us to decide if in the article we want to use the wpautop autoformat function or not.
As always to finish I leave my personal recommendation, which in this case I would say that if you understand how the
wpautop and using the appropriate line break type (pressing
Intro or pressing
Shift+Intro ) it is not necessary to disable this function, so In the end the choice is to everyone’s taste, whichever is more comfortable.