Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#20089 closed defect (bug) (fixed)

Visual editor messes up links in headers

Reported by: jikamens's profile jikamens Owned by:
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.3.1
Component: Editor Keywords:
Focuses: Cc:


Create a new post.

In HTML mode, put this in the post:

<h2><a name="foo" href="#bar">Foo</a></h2>

Switch to Visual mode.

Switch back to HTML mode.

Note how it now reads:

<h2><a name="foo" href="#bar"></a>Foo</h2>

I.e., the "</a>" tag has been moved, and the header is no longer a link.

This doesn't happen if you leave off the "name='foo'".

Change History (8)

#1 @nacin
12 years ago

Reproduced on trunk, which is TinyMCE 3.4.8.

#2 follow-up: @azaozz
12 years ago

  • Keywords close added

<a name="foo" href="#bar"> is not a link, it is an anchor. In HTML typically anchors don't wrap any text, so whether it's <h2><a name="foo" href="#bar">Foo</a></h2> or <h2><a name="foo" href="#bar"></a>Foo</h2> or even <a name="foo" href="#bar"></a><h2>Foo</h2> it works the same way (scrolls the page to it).

Proper links <h2><a href="">Foo</a></h2> work as expected.

#3 in reply to: ↑ 2 @jikamens
12 years ago

It is both an anchor and a link, which is perfectly valid HTML. It behaves as intended in every browser I've ever tried it in. The point is that I want to have a table of contents at the top of my document which links to all of the sections, and I want each of the section headers if clicked, to take the user back to the table of contents.

According to, "Authors may set the name and href attributes simultaneously in the same A instance."

TinyMCE is therefore clearly behaving incorrectly.

#4 @rosshanney
12 years ago

The id attribute can be used in place of name for this purpose. As stated on the same page you link above:

When the name or id attributes of the A element are set, the element defines an anchor that may be the destination of other links.

So your example would become:

<h2><a id="foo" href="#bar">Foo</a></h2>

TinyMCE seems to handle this correctly.

Of course, this doesn't change the fact that it should probably behave in the same way with name too.

#5 @dd32
12 years ago

I believe TinyMCE is following the XHTML spec, the name attribute was replaced by id in xhtml and html5 IIRC.

#6 @rosshanney
12 years ago

Looks like name on a elements is deprecated in XHTML ( and "obsolete but conforming" in HTML 5 (

#7 @ocean90
12 years ago

Duplicate: #21528

#8 @SergeyBiryukov
12 years ago

  • Keywords close removed
  • Milestone changed from Awaiting Review to 3.5
  • Resolution set to fixed
  • Status changed from new to closed

This is fixed in trunk (probably after TinyMCE update in [21228]).

Note: See TracTickets for help on using tickets.