Title: the_title_attribute
Published: April 25, 2014
Last modified: February 24, 2026

---

# the_title_attribute( string|array $args ): void|string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#wp--skip-link--target)

Sanitizes the current title when retrieving or displaying.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#description)󠁿

Works like [the_title()](https://developer.wordpress.org/reference/functions/the_title/),
except the parameters can be in a string or an array. See the function for what 
can be override in the $args parameter.

The title before it is displayed will have the tags stripped and [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)
before it is passed to the user or displayed. The default as with [the_title()](https://developer.wordpress.org/reference/functions/the_title/),
is to display the title.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#parameters)󠁿

 `$args`string|arrayrequired

Title attribute arguments. Optional.

 * `before` string
 * Markup to prepend to the title. Default empty.
 * `after` string
 * Markup to append to the title. Default empty.
 * `echo` bool
 * Whether to echo or return the title. Default true for echo.
 * `post` [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
 * Current post object to retrieve the title for.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#return)󠁿

 void|string Void if `'echo'` argument is true, the title attribute if `'echo'` 
is false.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#source)󠁿

    ```php
    function the_title_attribute( $args = '' ) {
    	$defaults    = array(
    		'before' => '',
    		'after'  => '',
    		'echo'   => true,
    		'post'   => get_post(),
    	);
    	$parsed_args = wp_parse_args( $args, $defaults );

    	$title = get_the_title( $parsed_args['post'] );

    	if ( strlen( $title ) === 0 ) {
    		return;
    	}

    	$title = $parsed_args['before'] . $title . $parsed_args['after'];
    	$title = esc_attr( strip_tags( $title ) );

    	if ( $parsed_args['echo'] ) {
    		echo $title;
    	} else {
    		return $title;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post-template.php#L81)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post-template.php#L81-L104)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#related)󠁿

| Uses | Description | 
| [get_the_title()](https://developer.wordpress.org/reference/functions/get_the_title/)`wp-includes/post-template.php` |

Retrieves the post title.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#)

| Used by | Description | 
| [feed_links_extra()](https://developer.wordpress.org/reference/functions/feed_links_extra/)`wp-includes/general-template.php` |

Displays the links to the extra feeds such as category feeds.

  | 
| [get_adjacent_post_rel_link()](https://developer.wordpress.org/reference/functions/get_adjacent_post_rel_link/)`wp-includes/link-template.php` |

Retrieves the adjacent post relational link.

  | 
| [get_the_content()](https://developer.wordpress.org/reference/functions/get_the_content/)`wp-includes/post-template.php` |

Retrieves the post content.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#comment-content-627)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_title_attribute/#comment-627)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%23comment-627)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%23comment-627)
 4.  **PHP with text args**
 5.      ```php
         printf(	'<a href="%s" title="%s">%s</a>',
         	get_permalink(),
         	the_title_attribute( 'echo=0' ),
         	get_the_title()
         );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%3Freplytocom%3D627%23feedback-editor-627)
 7.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#comment-content-625)
 8.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_title_attribute/#comment-625)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%23comment-625)
     Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%23comment-625)
 10. **Inline with array args**
 11.     ```php
         <a href="<?php the_permalink(); ?>" 
         	title="<?php the_title_attribute( array(
         		'before' => 'Permalink to: ',
         		'after'  => ''
         	) ); ?>">
         	<?php the_title(); ?>
         </a>
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%3Freplytocom%3D625%23feedback-editor-625)
 13.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/the_title_attribute/?output_format=md#comment-content-626)
 14.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_title_attribute/#comment-626)
 15. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%23comment-626)
     Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%23comment-626)
 16. **Inline with text args**
 17.     ```php
         /**
          * Output the post title.
          */
         function wpdocs_do_post_title() {
         	?>
         	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute( 'before=Permalink to: "&after="' ); ?>"><?php the_title(); ?></a>
         	<?php
         }
         ```
     
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F%3Freplytocom%3D626%23feedback-editor-626)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title_attribute%2F)
before being able to contribute a note or feedback.