I am trying to add a link in a nav in WordPress that links to a page's div that has a unique ID. I have done this on homepages: /#idname, but it is isn't working as a subpage: /subpagename/$id-name, is there a solution?
Linking to a div's ID in a WordPress subpage
637 Views Asked by wgoodman At
2
There are 2 best solutions below
0

Yes, you are correct, that was a typo. I should have been a pound mark. I figured out why the anchor wasn't working. The ID was in an API that gets loaded after the page loads so when you link to the page the ID wasn't loaded yet.
I ended up adding an anchor outside of the API and gave it a absolute position with CSS and it works. -- thanks for your answer.
Are you sure this is not just a typo
/subpagename/$id-name
where you're using$
instead of#
?You need two things to anchieve an hyperlink anchor: A defined and unique ID, set on a compatible html5 tag and an anchor.
The anchor should look something like this
<a href="#myAnchor">#</a>
.Source @ https://www.w3schools.com/tags/tag_a.asp
There is even an example page here https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_href_anchor
Additional information
As a general warning, what you're trying to do is condidered bad practice.
Source @ https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Examples