get_permalink for linking to specific place in a page

I am trying to link to specific place in a page from my front page , now I can only link to all page like this

<a class="info" href="<?php echo esc_url( get_permalink(1770) ); ?>" > Click to Explore </a>

but I want instead of page , link to exact place in a page, like in the middle , because in the page I use accordion and each panel of accordion are specific article , so I want to exact article. Is it possible to add to pageID 1770 some more information to do this. Thanks a lot.

Upvotes: 0

Views: 1395

Answers (1)

Peter
Peter

Reputation: 630

As @mszymborski said, use anchors.

Add an ID to the section/location of where you want the page to scroll to.

e.g. <h2 id="specific-location">Heading 2</h2>

in the code you provided, add the anchor name (#specific-location) at the end of the href.

<a class="info" href="<?php echo esc_url( get_permalink(1770) ); ?>#specific-location" > Click to Explore </a>

Upvotes: 1

Related Questions