How to add noindex to headings without posts in WordPress

You may have a situation where you have created several headings, but have not yet added posts to them. You probably don’t want empty categories without posts to be indexed by search engines. You can use wp_robots filter to add noindex to the robots meta tag:

add_filter( 'wp_robots', 'wpz_wp_robots' );
function wpz_wp_robots( $robots ) {

	if ( is_archive() && ! have_posts() ) {
		$robots['noindex']  = true;
		$robots['nofollow'] = true;
	}

	return $robots;
}

How useful is the publication?

Click on a star to rate it!

Average score 5 / 5. Number of grades: 1

No ratings yet. Rate it first.

Similar posts

How to override –wp–preset–color–black parameter in Gutenberg

In the Gutenberg block editor, you can override the –wp–preset–color–black parameter, which is responsible for the preset black color, using theme filtering or global styles. Ways to modify 1. Through theme.json If your theme supports theme.json, you can override the preset color in the settings.color.palette section. Example: This method automatically changes the value of the…
Read more

jquery how to get link on current site

In jQuery, you can get the current URL of the site using the JavaScript window.location object. Here are a few ways: 1. Full URL: 2. Current host (domain): 3. Current path (without domain): 4. Query string parameters: Using jQuery (optional): jQuery is not required here since access to window.location is provided by standard JavaScript. However,…
Read more

How to get next saturday in php

To get the next Saturday’s date in PHP, you can use the strtotime function with an appropriate string format. Here’s an example: This code: Thus, you’ll get the next Saturday’s date in the YYYY-MM-DD format.
Read more