How to include page title of wordpress post in the content possibly with a shortcode How to include page title of wordpress post in the content possibly with a shortcode wordpress wordpress

How to include page title of wordpress post in the content possibly with a shortcode


Refer to the codex: Shortcode API

function myshortcode_title( ){   return get_the_title();}add_shortcode( 'page_title', 'myshortcode_title' );

Add this to your theme's functions.php file.

Note that per the comments exchange between S.Visser and I in his answer - this solution will only work inside The Loop, while his will also work outside The Loop and so his is the more complete answer.


Add this to your theme, or make an plugin from it.

/* title to get the post title  */function getPageTitle() {  global $wp_query;  return get_post_title($wp_query->post->ID);}/* Add shortcode */add_shortcode('page_title', 'getPageTitle');


Found this solution on web hope it will help others who face the same problem as mine. Just add the below code to functions.php file or to the page_title plugin .php file.

add_filter('get_the_excerpt', 'show_shortcode_in_excerpt');add_filter('the_excerpt', 'show_shortcode_in_excerpt');function show_shortcode_in_excerpt($excerpt) {    return do_shortcode(wp_trim_words(get_the_content(), 55));}