permalink_anchor() WordPress Function

The permalink_anchor() function is used to create an anchor tag for a permalink. This function takes two parameters: the permalink and the text to display for the link. The permalink is the URL of the page to link to, and the text is the link text that will be displayed on the page.

permalink_anchor( string $mode = 'id' ) #

Displays the permalink anchor for the current post.


Description

The permalink mode title will use the post title for the ‘a’ element ‘id’ attribute. The id mode uses ‘post-‘ with the post ID for the ‘id’ attribute.


Top ↑

Parameters

$mode

(string)(Optional) Permalink mode. Accepts 'title' or 'id'.

Default value: 'id'


Top ↑

More Information

Usage:
permalink_anchor( $type );

Top ↑

Source

File: wp-includes/link-template.php

function permalink_anchor( $mode = 'id' ) {
	$post = get_post();
	switch ( strtolower( $mode ) ) {
		case 'title':
			$title = sanitize_title( $post->post_title ) . '-' . $post->ID;
			echo '<a id="' . $title . '"></a>';
			break;
		case 'id':
		default:
			echo '<a id="post-' . $post->ID . '"></a>';
			break;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
0.71Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More