skip to Main Content

I am working with the anchor link to another page in a specific element id. I have these two optional codes but these two doesn’t work. when I see the link on the programmer view, the link is right and it works fine. but when I try to click from the menu navbar it doesn’t link and nothing happened. here are the two optional codes I have using so far:

<a href="<?php echo home_url( '/#aboutus' ); ?>">About Us</a>

and

<a href="<?php echo esc_url( home_url( '/' ) ); ?>#aboutus">About Us</a>

basically my goal is from top page anchor to another page in a specific element id. and from another page anchor it to top page in a specific element id. is there any ways how to achieve this anchor link?

3

Answers


  1. You should do your code like this:

    <a href="<?php echo home_url(); ?>/aboutus">About Us</a>
    

    or

    <a href="<?php echo esc_url( home_url( '/' ) ); ?>/aboutus">About Us</a>
    
    Login or Signup to reply.
  2. This should work.

    <a href="<?php echo esc_url( home_url( '/' ) ) . "#aboutus"; ?>">About Us</a>
    
    Login or Signup to reply.
  3. If you are using this on home page then you should do like this:

    <a href="#aboutus">About Us</a>
    

    OR

    You want to do for inner page you should do like this:

    <a href="<?php echo home_url(); ?>/inner page slug/#aboutus">About Us</a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search