WordPress.org

Forums

How to add hyperlink code to the homepage in single.php? (10 posts)

  1. Emil_d08
    Member
    Posted 2 years ago #

    Hi,

    Is there any code that can create hyperlink to the homepage? I want to have a link to the homepage with anchor text that will appear automatically at the end of a new post. Something like this code:

    <p><?php wp_title('',true); ?></p>

    I use this code in single post (single.php) file after the 'content' code and it displays the post name in the end of the post in bold letters.

    Thanks!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    If you are inside the Loop, use <?php the_permalink;?>.

  3. Emil_d08
    Member
    Posted 2 years ago #

    Can you explain this with more details? How can i use anchor text with this code?

    Thanks!

  4. alchymyth
    Forum Moderator
    Posted 2 years ago #

    or possibly:
    http://codex.wordpress.org/Function_Reference/home_url

    example:
    <p><a href="<?php echo home_url(); ?>">link to home page</a></p>

  5. Emil_d08
    Member
    Posted 2 years ago #

    Thank you! This is what i was looking for.

  6. Emil_d08
    Member
    Posted 2 years ago #

    One more question: How would look the code if i want to create a hyperlink to a specific url, not the home page. Something like this url - http://domain.com/subpage/

    Thanks!

  7. Jason
    Member
    Posted 2 years ago #

    <a href="<?php echo home_url('/subpage/'); ?>">link to home page</a>

  8. Emil_d08
    Member
    Posted 2 years ago #

    It doesn't seem to work. It doesn't show a subpage url only the home page url.

  9. Jason
    Member
    Posted 2 years ago #

    The code should work. See http://codex.wordpress.org/Function_Reference/home_url. Post your code and I'll have a look.

  10. Emil_d08
    Member
    Posted 2 years ago #

    Well, it worked but i used site_url instead of home_url.
    Thanks for the link.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.