Archived topic
Is there a GP shortcode or preferred method to print the Page Title?
3 replies · Started by Henry on January 21, 2021
I am using a custom post type and I need to add the Post Title to my template. I know that you can hard code that into a template but I prefer to use a shortcode like this:
function post_title_shortcode(){
return get_the_title();
}
add_shortcode('post_title','post_title_shortcode');
Just asking in case there is a "preferred" way?
Much the same way that GP has a copyright date shortcode right? Is there something similar for the Post Title?
I don't want to duplicate efforts, hence the question, thanks.
Hi there,
no GP doesn't add ANY shortcodes. So the method you're using is correct.
Although if you're adding that to a template then you're better off just making the function call for the title as opposed to wrapping it in a shortcode..
thanks David
You're welcome