2

I am trying to understand some basic concepts of WordPress.

Let's say I am a coder and I made a template for my client. I am at the point when some basic layout of the page is complete and now I want to fill in some text. I will use Wordpress Pages for this so my client can edit the texts whenever he wants.

Now I want to add the client's address on the page. It requires using some DIV structure to have the address nice on the page. I add this code directly to the Contact Page using TinyMCE (edit post) and HTML tab. I save the article and voila, the address seems to have the correct data and correct CSS styles.

What happens to me now is that I go back to Page editing, it automatically opens the HTML tab (because I used it last time) and when I go to Visual tab, I do nothing else but going back to HTML tab, my code breaks and if I save the page at this point, my client address layout breaks too.

This code:

<div class="item">
<div class="content">

Becomes this:

<div class="item">

&nbsp;
<div class="content">

And it is all because I switch to Visual tab and back to HTML tab.

Moreover, this new "paragraph" actually becomes

<p></p>

And that is what breaks my page in the end.

What is the solution for this?

2
  • I would create a custom shortcode; and a custom TinyMCE button. Then, you could let your users enter the address in a visual window, and insert the populated shortcode directly into the editor. Div elements are difficult to work with in the editor.
    – josh
    Commented May 24, 2014 at 8:40
  • Thank you for your advice. My biggest nightmare at the moment is that /new line/& nbsp; and that it renders this as <p></p> I need to get rid of this first.
    – user52107
    Commented May 24, 2014 at 9:08

5 Answers 5

4

You can add this code to your function.php file of your theme

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

or you can use this plugin for easier control

0

This has been a frustration for me before, so you are not alone :-) Fortunately the automatic formatting in WordPress is easy to disable.

Put this in your themes functions.php file...

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

Apparently since I am using WPGlobus plugin for multiple languages this would not work for me. Just wanted to write it here for somebody to save a few hours trying to disable auto formating while using WPGlobus plugin.

The solution with WPGlobus plugin:

Apparently it passes everything trough the wpautop function in the plugin. It is in the file wp-content\plugins\wpglobus\includes\class-wpglobus.php

I changed

$post_content_autop = wpautop( $post_content ); 

to

$post_content_autop = $post_content;

in the file and it disabled all autoformatting for me while using WPGlobus plugin.

Hope this helps somebody not to go through what I just did.

2
  • 1
    You should never change plugin files if you are not the author of the plugin. This is just a poor solution that should not be followed Commented Oct 13, 2015 at 19:23
  • You should do what You like, and never listen to authorities if You know what You are doing. Also it is good to note somewhere in the code that You changed it, unless You are using code versioning like Git, then there is no need of noting things.
    – Marecky
    Commented Apr 13, 2017 at 12:07
0

Per the OP's answer that was added within the question:

TinyMCE Advanced pretty much solved all of my problems...

0

I made a plugin called Ignore Code to address this issue.

Note: When you put the code inside that shortcode it won't show up in the visual editor at all.

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.