Skip to content

Is there any conditional function to check if a query is from the query loop block? #42655

Answered by t-hamano
catkit asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @catkit,

Sorry for the late reply.

I think what you want to do can be solved by the following approach:

  • Apply a specific class to the post content block whose content you wish to rewrite.
  • Use the render_block_{blockname} hook to rewrite content only if that class is present.

Here is a sample:

add_filter( 'render_block_core/post-content', function ( $block_content, $block ) {
	// For the post content block that doesn't have a class name, output the content as is.
	if ( ! isset( $block['attrs']['className'] ) ) {
		return $block_content;
	}
	// For the post content block that doesn't have a specific class name, output the content as is.
	if ( 'your-class' !== $block['attrs']['className']…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by aristath
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants