WP_Customize_Nav_Menu_Item_Setting::get_original_title( object $item ): string

In this article

Get original title.

Parameters

$itemobjectrequired
Nav menu item.

Return

string The original title.

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

VersionDescription
4.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.