WordPress permalink_anchor() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Prints an anchor

Definition

In WordPress, permalink_anchor() prints a small anchor tag with an ID for the current post. The anchor is empty, so it shows nothing on the page. It only marks a spot.

You can then link to that spot with a jump link, such as #post-42. It is helpful on pages that show many posts, like archives. Use it inside the Loop.

Syntax

Call it at the top of each post in the Loop.

WordPress
<?php permalink_anchor(); ?>
CallWhat it does
permalink_anchor()Print an anchor with the ID post-42.
permalink_anchor( 'id' )The same as the default.
permalink_anchor( 'title' )Print an anchor made from the post title and ID.

It prints the anchor. It works on the current post, so use it in the Loop.

Full declaration
WordPress
permalink_anchor( string $mode = 'id' ): void

Parameters

ParameterDescription
$modestring. id (default) makes an ID such as post-42. title makes an ID from the post title, such as hello-world-42.

Return Value

Return ValueDescription
voidNothing is returned. An anchor tag is printed.

WordPress Examples

Three short examples. Each one shows the code and what it prints or does.

Example 1 — Print the default anchor

Call it inside the Loop.

WordPress
<?php
while ( have_posts() ) {
  the_post();
  permalink_anchor();
  the_title( '<h2>', '</h2>' );
}

How It Works

  1. The Loop sets the current post.
  2. permalink_anchor() prints an empty anchor with the ID post-42.
  3. The title follows the anchor.

Example 2 — Use the title mode

Make a readable ID from the post title.

WordPress
<?php
permalink_anchor( 'title' );

How It Works

  1. The title Hello world becomes hello-world.
  2. The post ID is added at the end.
  3. The ID stays unique even if two posts share a title.

Example 3 — Add a jump link

Create a link to the anchor, for example from a table of contents.

WordPress
<?php
echo '<a href="#post-' . get_the_ID() . '">Jump to this post</a>';

How It Works

  1. get_the_ID() returns the post ID.
  2. The link points to the same ID the anchor uses.
  3. Clicking it scrolls the page to the anchor.

Frequently Asked Questions

It prints an empty anchor tag with an ID for the current post, so you can link to that spot on the page.
No. It is an empty tag. It only marks a position.
id makes an ID like post-42. title makes an ID from the post title and the post ID.
Inside the Loop, for example on archive pages that show many posts.
No. the_permalink() prints the URL of the post. permalink_anchor() prints a marker tag on the current page.

Next: site_url()

Return the site URL of the current site (where WordPress is installed), with an optional path.

site_url() tutorial →

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