generateblocks icon indicating copy to clipboard operation
generateblocks copied to clipboard

Query block - how to get query id on paged pages to add custom meta tags

Open madanpraba opened this issue 3 years ago • 2 comments

Description Pagination in the query block adds the query variable "query-queryid-page" (e.g. /?query-ef108cb9-page=2) to display the result on the page. In terms of SEO, sometimes we need to add the "noindex" meta tag to the paginated pages. Is it possible to get the randomly generated query block IDs to use in custom_query_var ... or do you have a plan for creating filters?

madanpraba avatar Jun 18 '22 09:06 madanpraba

@madanpraba currently we don't have a way of adding the noindex. But I'm keeping this as feature for the next release. Thanks

JeanPaiva avatar Jun 21 '22 00:06 JeanPaiva

This is something we should look at as soon as 1.8.0.

A "dirty" solution would be to do something along the lines of this:

add_action( 'wp_head', function() {
	$params = $_GET;
	
	foreach ( (array) $_GET as $key => $value ) {
		$query_param = preg_match( '/query-(\w+)-page/', $key, $matches );
		
		if ( ! empty( $matches ) ) {
			if ( isset( $_GET[ $matches[0] ] ) && $_GET[ $matches[0] ] > 1 ) {
				echo '<meta name="robots" content="noindex" />';
			}
		}
	}
}, 0 );

I'd prefer something more concrete, though.

tomusborne avatar Oct 18 '22 02:10 tomusborne