I’ve search around for how to remove unwanted HTML tags which are added by TinyMCE, etc.
The only solution I’ve come across remove all p tags by disabling various filters.
This isn’t any good for semantic page structure.
Does anyone have any tips which could point me in the right direction?
You can customize very many aspects of TinyMCE’s behaviour with the use of the filter tiny_mce_before_init.
So, if you can find out exactly what is bothering you, you can more than likely do something about it.
For example, adding the following code to your functions.php file will ensure that TinyMCE produces <br /> tags instead of <p> tags when you press enter.
Thanks for the reply.
My problem is nearly everything is being wrapped with p tags, even header tags and div tags.
I’ve wrote a few short codes which output markup for the likes of jQuery accordions. I need the user to have the ability to provide clean and well formatted shortcode structure so they can maintain it easier. The only way I’ve found which will sort the issue is to remove every single break within the structure but that makes it almost unmaintainable.
I’ve also got another short tag which simply enters an openning and closing div tag in the content to be styled as a divider and even that is getting wrapped.
There is also a function called wpautop which changes double line-breaks in the text into HTML paragraphs (<p>…</p>).
You can disable this from within functions.php:
Other than that there is a good plugin which alows you to wrap code in [raw] tags and have Wordpress leave it as it is (i.e. not format it): http://wordpress.org/extend/plugins/raw-html/
If you set the wpauto filter so that those extra p elements get removed, why not then use the HTML (instead of visual) view of the editor? That would do what you want. If the user enters markup anyway, then there’s no reason not to use the HTML view, plus, that way you get exactly what you have entered and WP does not add extra markup that way either.
That method isn’t any good.
I added the clean ‘markup’ i provided in a previous post in the HTML editor, switched to the visual editor and then immediately back and it added the unwanted markup.
I need to have it so that the markup is clean and using the HTML editor is not possible for a lot of users as they may not have HTML experience and many of which will not want to gain any experience.
For now i’ve implemented a cleanup function which removes all the unwanted markup surrounding the shortcode tags, ie ‘<p>[shortcode_name]</p>’ is cleaned up to ‘[shortcode_name]’, etc.
The visual editor was never meant for users to add their own markup to begin with, so naturally it will add markup, that’s the point of the visual editing mode.
Have you looked at alternative text entry methods? E.g. using something like Markdown or Textile? They’re a lot cleaner but may not be for everyone.