Uses
| Uses | Description |
|---|---|
| wp-includes/formatting.php: sanitize_title() | Sanitizes a string into a slug, which can be used in URLs or HTML attributes. |
| wp-includes/post.php: get_post() | Retrieves post data given a post ID or post object. |
Displays the permalink anchor for the current post.
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.
(string) (Optional) Permalink mode. Accepts 'title' or 'id'.
Default value: 'id'
permalink_anchor( $type );
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;
}
} | Version | Description |
|---|---|
| 0.71 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/permalink_anchor