WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] hyperlink branding page area to a specific post or page (14 posts)

  1. Mark Shirley
    Member
    Posted 1 year ago #

    Hi - how can i hyperlink the branding image area to a specific page not the home page of the site I think this is the code below in the header file that does this but I could be wrong.

    <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
  2. esmi
    Forum Moderator
    Posted 1 year ago #

    What theme are you using?

  3. Mark Shirley
    Member
    Posted 1 year ago #

    Hi esmi

    twenty-eleven child theme we are using the home page with no menu and need the internal pages to link to a specific page other than the home page.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Well, you're on the right track. In your child theme's header.php template file, you could use something like:

    <?php if( is_front_page() || is_home() ) $banner_url = esc_url( home_url( '/' ) );
    else $banner_url = 'http://example.com/';?>
    <a href="<?php echo $banner_url; ?>">

    Then replace http://example.com/ to your chosen url. Is this new linked page one of your WP site or is it for an external site?

  5. Mark Shirley
    Member
    Posted 1 year ago #

    Well done esmi - that works fine - top man - Thanks bundles :-)

  6. Mark Shirley
    Member
    Posted 1 year ago #

    or woman Ha Aa

  7. Mark Shirley
    Member
    Posted 1 year ago #

    PS - just seen the last bit of your answer it was an internal page - cheers

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    If it's an internal page, the best approach (as opposed to hard coding the url) would be to make a note of that page's ID and then use get_permalink( $id );. That would make the link usable even if you changed your permalink structure.

  9. Mark Shirley
    Member
    Posted 1 year ago #

    Wow thanks esmi - no idea how to code that one im a cut and paste php guy - the code you gave me seems to work fine for an external page.

  10. Mark Shirley
    Member
    Posted 1 year ago #

    sorry ment to say internal on post above

  11. Mark Shirley
    Member
    Posted 1 year ago #

    Do you mean something like this esmi

    <?php if( is_front_page() || is_home() ) $banner_url = esc_url( home_url( '/' ) );
    else $banner_url = 'http://example.com/';?>
    <a href="<?php echo get_permalink( 268 ); ?>
  12. Mark Shirley
    Member
    Posted 1 year ago #

    Ha - just used this code below for the page id seems to work

    <a href="<?php echo get_permalink( 265 ); ?>">
  13. esmi
    Forum Moderator
    Posted 1 year ago #

    Yep - that's exactly what I meant. Permalink-structure-change proofed!. :-)

  14. Mark Shirley
    Member
    Posted 1 year ago #

    Thanks again got both ways now :-)

Topic Closed

This topic has been closed to new replies.

About this Topic