I am trying to write a shortcode to display the page title. I only got the archive title to work, but not custom post type category and single post. Can anyone shed light how to do this?
The reason for going this path is Elemenentor theme builder generating too much code for simple page title and subheading inside secondary header that is masked wrap around an image. I use the shortcode widget to insert the code and style it.
So far this is what I have written:
// Page Title inside shortcode
function page_title_sc( ) {
$title = ('Page Title');
if ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
}
elseif ( is_page() ) {
$title = single_post_title();
}
return apply_filters( 'page_title_sc', $title );
}
add_shortcode( 'page_title', 'page_title_sc' );