wppaste
WordPress

permalink_anchor( string $mode = 'id' )

Since
0.71
Source
wp-includes/link-template.php:78
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.

Parameters

$modestringoptional
Permalink mode. Accepts 'title' or 'id'. Default 'id'.Default: 'id'

Uses · 2

  • get_post()Retrieves post data given a post ID or post object.
  • sanitize_title()Sanitizes a string into a slug, which can be used in URLs or HTML attributes.

Source

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;	}}

History

Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.