permalink_anchor

Definition:
function permalink_anchor($mode = 'id') {}

Display permalink anchor for 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.

Parameters

  • string $mode: Permalink mode can be either ‘title’, ‘id’, or default, which is ‘id’.

Source code

function permalink_anchor($mode = 'id') {

	global $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;

	}

}

2501

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: