Get original title.
Parameters
$item
objectrequired- Nav menu item.
Source
protected function get_original_title( $item ) {
$original_title = '';
if ( 'post_type' === $item->type && ! empty( $item->object_id ) ) {
$original_object = get_post( $item->object_id );
if ( $original_object ) {
/** This filter is documented in wp-includes/post-template.php */
$original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID );
if ( '' === $original_title ) {
/* translators: %d: ID of a post. */
$original_title = sprintf( __( '#%d (no title)' ), $original_object->ID );
}
}
} elseif ( 'taxonomy' === $item->type && ! empty( $item->object_id ) ) {
$original_term_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
if ( ! is_wp_error( $original_term_title ) ) {
$original_title = $original_term_title;
}
} elseif ( 'post_type_archive' === $item->type ) {
$original_object = get_post_type_object( $item->object );
if ( $original_object ) {
$original_title = $original_object->labels->archives;
}
}
$original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) );
return $original_title;
}
Hooks
- apply_filters( ‘the_title’,
string $post_title ,int $post_id ) Filters the post title.
Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.