permalink_anchor

Displays the permalink anchor for the current post.

Description

permalink_anchor( (string) $mode = 'id' ); 

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 (1)

0. $mode — Optional. (string) => 'id'
Permalink mode. Accepts title or id.. Default id..

Usage

  1. if ( !function_exists( 'permalink_anchor' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Permalink mode. Accepts 'title' or 'id'. Default 'id'. 
  5. $mode = 'id'; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = permalink_anchor($mode); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function permalink_anchor( $mode = 'id' ) { 
  2. $post = get_post(); 
  3. switch ( strtolower( $mode ) ) { 
  4. case 'title': 
  5. $title = sanitize_title( $post->post_title ) . '-' . $post->ID; 
  6. echo '<a id="'.$title.'"></a>'; 
  7. break; 
  8. case 'id': 
  9. default: 
  10. echo '<a id="post-' . $post->ID . '"></a>'; 
  11. break;