Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Why does my code automatically change? WordPress


Here's the deal. When I go into the html view of my wp and type in the following code:

<a name="1">Text</a>

And then click normal view and click back to html view, the code changes automatically to:

<a name="1"></a>Text

It does not do this for other people, but it consistently does it for me. Here is some additional info:

It started with wp 3.2
It happens across different computers with different ip addresses
It happens in IE, Firefox, and Chrome
It happens when I log in under different users

Why does this happen and how can I get it to stop happening?

Answers (5)


Jurre Hanema answers:

I can confirm that this problem exists. I am using Wordpress 3.2.1 with no plugins and the default theme and I am also affected by this issue.

Steps to reproduce:
- Go edit a post
- Switch to the HTML-editor and enter this exact text: <a name="1">test</a>
- Switch back to the Wysiwyg-editor and again to the HTML-editor
- The code is now changed to <a name="1"></a>test

I think this is a issue with how TinyMCE handles these anchors. I have found the following possible simple solution:

Use the id-attribute instead of name: <a id="some_id">test</a> works and allows you to jump to that point on the page just like <a name="some_name"> does.


Abdessamad Idrissi answers:

This is related to the tinyMC XHTML behaviour; it forces the use of HTML [[LINK href=""]]Standard Attributes[[/LINK]] the "name" attribute is optional for the anchor tag.
This issue was already reported on the [[LINK href=""]]wordpress trac[[/LINK]] and the conclusion is:
[[LINK href=""]]<em>From HTML point of view <a name="bob">Inside</a> is exactly the same as <a name="bob"></a>Inside. The anchor is a hidden pointer to where the page should scroll when accessed with http://someurl#anchor.</em>[[/LINK]]
One question; Why you want to use the name attribute? Maybe you should be using the ID attribute.
hope it helps :)


Jerson Baguio answers:

try this plugin maybe it will solve your issue


Julio Potier answers:


Can you list your plugins here ? I never heard of that before.

Thank you.

Julio Potier comments:

I think Jurre Hanema got the right answer :o


Kannan C answers:

something(from plugin fn or from your own theme fn) is interfere with the content. A quick fix for it is you can disable auto formatting for the specific area using shortcode

function my_formatter($content) {
$new_content = '';
$pattern_full = '{(\[raw\].*?\[/raw\])}is';
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

foreach ($pieces as $piece) {
if (preg_match($pattern_contents, $piece, $matches)) {
$new_content .= $matches[1];
} else {
$new_content .= wptexturize(wpautop($piece));

return $new_content;
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);

usage: [raw]Unformatted code[/raw]