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?

  • 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 May 24 '14 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 May 24 '14 at 9:08
3

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.

  • 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 – Pieter Goosen Oct 13 '15 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 Apr 13 '17 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, privacy policy and cookie policy

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