Is there a way to stop WordPress from automatically inserting <br>
tags when adding returns in the WordPress text editor.
I would like for it to behave more like a code editor where I can structure the code how I like and make it easy to read.
The code I am using in the editor is:
[one_third][team_member image_url="team_member.jpg" name="Laser vision" role="WordPress Designer"][custom_button url="#"]For more information[/custom_button][/team_member][/one_third][one_third][team_member image_url="team_member.jpg" name="Laser vision" role="WordPress Designer"][custom_button url="#"]For more information[/custom_button][/team_member][/one_third][one_third][team_member image_url="team_member.jpg" name="Laser vision" role="WordPress Designer"][custom_button url="#"]For more information[/custom_button][/team_member][/one_third]
I would like to structure it like this so it is easier to read and edit:
[one_third]
[team_member image_url="team_member.jpg" name="Laser vision" role="WordPress Designer"]
[custom_button url="#"]For more information[/custom_button]
[/team_member]
[/one_third]
[one_third]
[team_member image_url="team_member.jpg" name="Laser vision" role="WordPress Designer"]
[custom_button url="#"]For more information[/custom_button]
[/team_member]
[/one_third]
[one_third]
[team_member image_url="team_member.jpg" name="Laser vision" role="WordPress Designer"]
[custom_button url="#"]For more information[/custom_button]
[/team_member]
[/one_third]
However, when do this there will be invisible <br>
tags added to the post content which will mess up the layout of my page.
The answer by shea is not ideal as in many cases:
<br>, <p>
etc. You want it as a default behavior for your WP visual composer which the above code will deletedefault core behavior of WP – for example such a thing will not pass
on ThemeForest
As I can see you mainly have issues with you shortcodes. The right way to approach this is not to change the default behavior (hack the core) but to just filter the content. So just add a filter and in a variable pass an array of your shotrcodes you want to filter like this:
The content inside will be filtered and therefore your shortcodes will be free of
<br>, <p>
etc. but the other parts of content – for example standard text in the WP editor created by user – will still have full functionality of WP.References:
The
wpautop()
function adds<p>
and<br>
tags to your content in order to preserve line breaks. If you would rather add these tags yourself, then you can remove the filters which apply this function to the post content:If you would like to keep the automatic paragaraph creation (inserting
<p>
tags) and just remove the additional<br>
tags, you can use this code instead:See this link if you’re not sure where to put this code.
Install the plugin “Don’t Muck My Markup”.
It adds a checkbox option to each page disabling auto insertion of
<p>
and<br>
tags.There is also an option to do this site-wide.
Probably it Ãs the text editor that makes a mess. This is what I did:
I use TinyMCE. Under settings for the text editor, I unchecked “Stop removing the “< p >” and “< br / >” tags when saving and show them in the HTML editor”. Worked for me.
Maybe you could simply use
do_shortcode()
if all you have in your content is shortcodes, as long as you don’t have any other content that need the filters.I don’t know the context, but if you’re in the loop :
echo do_shortcode($post->post_content);
Borek’s answer didn’t work for my use case, which is writing raw HTML.
For that I used the Code Snippets plugin (lets you easily add arbitrary PHP snippets that get run) to create a snippet for an
[html][/html]
shortcode. What’s cool about this shortcode is that it’s compatible with the toggle-wpautop plugin which lets you disable the automatic insertion of<br>
and<p>
tags on an entire post. You can use either, mix & match.This function only removes the
<p>
and<br>
tag for the shortcode.for those who are not familiar with code hack or don’t want to use plug in , you can do this.
1) copy all current code from WP pages ( text editor)
2) then paste to notepad and continue require edit ( add short code , html code or css code)
3) Copy paste from notepad to the same scree on WP pages ( text editor)
4) Hit [UPDATE] button which is located at the right hand side of the same WP pages to publish the pages
5) Finally preview it on live site