I have a header file in WordPress theme which always shows site title after the creation of a new page because of code <?php echo esc_html( get_bloginfo( 'name' ) ); ?> but I want it to replace with current page title instate of site name so, what would be PHP code for that?

  • Are you referring to the <title> tag? – Jacob Peattie Nov 12 '18 at 6:24

Try below code.

global $post;
echo esc_html( get_the_title($post->ID) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.