Show title on blog page

[ad_1]

ying

(@yingscarlett)

Hi there,

Try this snippet, replace Blog with the actual title you want.

add_action('generate_before_main_content', function() {
	if (is_home()) {
	echo '<header class="page-header" aria-label="Page">
          <h1 class="page-title">Blog</h1>
		  </header>';
	}
});

Thanks much @yingscarlett, it works, although I was hoping to find a solution similar to the one I posted above. Half of my problem was that I didn’t know is_home returns true even if the blog page is not the home page. I checked the WP reference and it was indeed trivial.

But I don’t get it how the blog page is different from archive pages like tags, categories, search. They all can display the title without injecting extra markup. If this went into the header template it’d be fine but in functions.php it’s sort of a hack.

This is what I finally added:

 echo '<h1 class="entry-title">' . get_the_title(19) . '</h1>';

I know it’s an extra db query but a hard coded title just didn’t feel elegant.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer