Black Friday Sale! Get up to $40 off GP Premium!Learn more

Code for anchors changes after it's entered

Home Forums Support Code for anchors changes after it's entered

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #167252
    NBC

    Here’s what I type:

    <a name="The Anchor"><highlight-text><h3>The Anchor</h3></highlight-text></a>

    Here’s what I see when I load the page in a separate browser tab and view the source code (this is in Firefox):

    <a name="The Anchor"><highlight-text><br />
    <h3>The Anchor</h3>
    <p></highlight-text></a><br />
    

    How do I stop these unwanted additions? Those <br />s add a large amount of white space above and below what’s supposed to be a section title. I’m jumping to sections on a page from custom menu items.

    BTW, switching from “Text” to “Visual” view of the page I’m editing broke the page content completely.

    • This topic was modified 4 years, 10 months ago by NBC.
    #167287
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    The WP editor can act strange sometimes when trying to make sure your content is output correctly.

    Try adding an HTML comment in between your anchor:

    <a name="The Anchor"><! -- anchor --></a>

    That should stop the editor from messing with it.

    #167309
    NBC

    Now instead of

    <a name="The Anchor"><highlight-text><h3>The Anchor<! -- anchor --></h3></highlight-text></a>
    

    I have the following:

    <p><a name="The Anchor"><highlight-text><br />
    <h3>The Anchor<! -- anchor --></h3>
    <p></highlight-text></a><br />
    

    Hmm, maybe I don’t need anchors.

    #167392
    Tom
    Lead Developer
    Lead Developer

    Where is the highlight text div coming from? Maybe you have a plugin causing issues?

    Are you adding the code using the “Text” tab?

    #167422
    NBC

    <highlight-text> is custom CSS that adds a highlighter-pen appearance where it’s applied. It’s defined in the style.css file of my child style, as follows:

    highlight-text {background-color:#FFFF00;}

    I am using the Text editor. I experimented with Visual once, hated it, went back to Text, and hated Visual even more when I saw what it did to my code.

    I’m beginning to think I have no alternative but to look for a replacement editor. After looking for an hour at alternatives, it appears it’ll cost me money to do so. This one looks like the favorite.

    #167471
    Tom
    Lead Developer
    Lead Developer

    Hmm, you shouldn’t have to use another editor at all.

    When you open the “Text” tab of your editor, what does the code look like? Is it all messed like when you view the live site?

    #167486
    NBC

    The only workable solution was to separate the anchor link on a line above the subhead. Otherwise, either the editor added tons of blank space above and below the subhead, or the anchor link jumped to the beginning of the paragraph below the subhead.

    <smh>

    #167541
    Tom
    Lead Developer
    Lead Developer

    You can also use an ID in the H3:

    <h3 id="my-anchor">Heading</h3>

    Then link to #my-anchor

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.