• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / the_title_attribute() – Sanitize the current title when retrieving or displaying.

You appear to be a bot. Output may be restricted

Description

Sanitize the current title when retrieving or displaying.

Works like 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() before it is passed to the user or displayed. The default as with the_title(), is to display the title.

Usage

$void|string = the_title_attribute( $args );

Parameters

$args
( string|array ) optional – { Title attribute arguments. Optional.
$before
( string ) optional – Markup to prepend to the title. Default empty.
$after
( string ) optional – Markup to append to the title. Default empty.
$echo
( bool ) optional – Whether to echo or return the title. Default true for echo.
$post
( WP_Post ) optional – Current post object to retrieve the title for. }

Returns

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

Source

File name: wordpress/wp-includes/post-template.php
Lines:

1 to 24 of 24
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 on GitHub View on Trac

Published: 25th November 2019 | Last updated: 25th November 2019

Primary Sidebar

Information

Function name: the_title_attribute
Plugin ref: WordPress
Version: 5.6.2
Sourcefile: wp-includes/post-template.php
File ref: wp-includes/post-template.php
Deprecated?: No
API Letters: A,T

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites