astra_get_the_title( int $post_id, bool $echo = false )
Wrapper function for get_the_title()
Description
Return title for Title Bar and Normal Title.
Parameters
- $post_id
-
(int) (Optional) default to 0. Post id.
- $echo
-
(bool) (Optional) default to false. Whether to display or return.
Default value: false
Return
(string|void) String if $echo parameter is false.
Source
File: inc/core/common-functions.php
function astra_get_the_title( $post_id = 0, $echo = false ) {
$title = '';
if ( $post_id || is_singular() ) {
$title = get_the_title( $post_id );
} else {
if ( is_front_page() && is_home() ) {
// Default homepage.
$title = apply_filters( 'astra_the_default_home_page_title', esc_html__( 'Home', 'astra' ) );
} elseif ( is_home() ) {
// blog page.
$title = apply_filters( 'astra_the_blog_home_page_title', get_the_title( get_option( 'page_for_posts', true ) ) );
} elseif ( is_404() ) {
// for 404 page - title always display.
$title = apply_filters( 'astra_the_404_page_title', esc_html__( 'This page doesn\'t seem to exist.', 'astra' ) );
// for search page - title always display.
} elseif ( is_search() ) {
/* translators: 1: search string */
$title = apply_filters( 'astra_the_search_page_title', sprintf( __( 'Search Results for: %s', 'astra' ), '<span>' . get_search_query() . '</span>' ) );
} elseif ( class_exists( 'WooCommerce' ) && is_shop() ) {
$title = woocommerce_page_title( false );
} elseif ( is_archive() ) {
$title = get_the_archive_title();
}
}
$title = apply_filters( 'astra_the_title', $title, $post_id );
// This will work same as `get_the_title` function but with Custom Title if exits.
if ( $echo ) {
echo $title; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
return $title;
}
}
Expand full source code Collapse full source code View on Trac