• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Add anchor links to all headlines in the_content.

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Add anchor links to all headlines in the_content.

This topic is: resolved

Tagged: anchor tags, HTML bookmarks, sub headings

  • This topic has 2 replies, 2 voices, and was last updated 2 years, 12 months ago by Hans Schuijff.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • June 5, 2020 at 1:09 pm #499170
    Hans Schuijff
    Member

    When I visit github, or websites like css-tricks.com, I see that every heading shows an anchor sign (sometimes on hover) that links directly to that header. It seems to become more popular, since I have come across it more in the last year.

    My question is: how is it created, considering that I don't think the links are manually added to the content. I could probably do it with js, but I rather do something server side using php.

    The resulting html should be something like this:

    <h3 id="article-header-id-0" class="has-header-link">
    	<a class="article-headline-link" href="#article-header-id-0">#</a>
    	This is a headline of the third level
    </h3>

    I've searched for it but couldn't find any 'how to' article on the subject, so I'm asking... can any of you offer (or point to) a code example, that creates something like the above html using php starting with a normal headline wrapped in heading tags?

    Thanks,

    Hans

    June 10, 2020 at 7:41 pm #499228
    Brad Dalton
    Participant

    1. You can do this manually using HTML in the editor https://www.w3schools.com/html/html_links_bookmarks.asp

    2. or use jQuery to target heading tags within the content area.


    Tutorials for StudioPress Themes & WooCommerce.

    June 11, 2020 at 3:55 am #499238
    Hans Schuijff
    Member

    Hallo Brad,

    Thanks for the suggestions. I could probably do it with jquery, but I wanted some automation on server side, so not to violate amp rules or be dependent on user entry. I knew it should probably entail some regular expression, but didn't want to invent the wheel for something that is already out there.

    One of the websites that uses it (CSS-tricks) has responded that they use a plugin and I found a plugin in the registry called "Add anchor links" that seems to do the job nicely and looks well coded. So I'm mostly happy with it.

    Thanks again for offering your help.

    Hans

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Add anchor links to all headlines in the_content.’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble