WordPress Links

Beginner
7 min read
Updated: Nov 2026
2 examples
Core concept

Definition

Link functions are helpers that give you the address of something on your site: a post, the home page, the login page, a search page, or an edit screen. You use them in themes and plugins, so you never type a domain by hand.

Many of them come in pairs. The the_ version prints the link, and the get_ version returns it. Edit links, such as edit_post_link(), appear only for logged-in users who can edit.

Safe by habit.

When a function returns a URL, wrap it with esc_url() before you print it. Functions that print a URL, such as the_permalink(), already escape it for you.

Syntax

Print a post link, then build the home page link.

WordPress
<a href="<?php the_permalink(); ?>">Read more</a>

<?php echo esc_url( home_url( '/' ) ); ?>

Print vs Get Twins

If you want to print, use the left column. If you want a value to store or change, use the right column.

Home URL vs Site URL

They are the same on most sites. They differ when WordPress is installed in a subfolder.

home_url()site_url()
It isThe front of your siteWhere WordPress is installed
Examplehttps://example.comhttps://example.com/wp
Use it forLinks visitors clickwp-login.php, wp-admin
Guideshome_url(), get_home_url()site_url(), get_site_url()
Edit links need a login.

edit_post_link(), edit_comment_link(), and edit_tag_link() print nothing for visitors. They only show for users who can edit.

WordPress Examples

Two short examples with sample output.

Example 2 — Show an edit link

One line adds an Edit link that only admins and editors can see.

WordPress
<?php
edit_post_link( 'Edit this post', '<p class="edit-link">', '</p>' );

How It Works

  1. edit_post_link() checks if the current user can edit the post.
  2. If yes, it prints the link with your before and after HTML.
  3. If not, it prints nothing, so visitors never see it.

Next: WordPress Link Functions

Now that you know the basics, open the functions index for all 25 guides.

Full list: WordPress Link Functions index (/wordpress/link/function).

Frequently Asked Questions

They are helper functions that print or return URLs, such as post links, the home URL, the site URL, search links, and edit links.
the_permalink() prints the URL. get_permalink() returns it. Use get_permalink() when you want to store it or place it inside your own HTML.
home_url() is the address of your front page. site_url() is where WordPress is installed. They differ when WordPress is in a subfolder.
A returned URL may contain special characters. esc_url() makes it safe to print inside an href. Functions that print the URL, such as the_permalink(), already escape it.
Edit links such as edit_post_link() check the user. They print only for logged-in users who can edit that item.
Open the WordPress Link Functions index. It lists all 25 guides in short tables.

Browse every link function

Open the functions index for simple guides with examples and FAQs.

Link Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful