How to check if on page 1 (not page 2, 3, etc) when rendering a block #65684
-
I'm working on rendering a custom block in WordPress and need to conditionally display it only on the first page (page 1) of a paginated query or on the front page. The block should not appear on subsequent pages like page 2, 3, etc. I've tried using Is there a reliable way to check if I am on page 1 (or the first page of a paginated query) when rendering a block? Please help me. PS I'm using my custom block theme with custom Gutenberg blocks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, looking at the way the Post Template block (https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/post-template/index.php) is rendered, I think you can use the “render_block” filter for your block type and derive the query context in a similar way this block does. |
Beta Was this translation helpful? Give feedback.
Hi, looking at the way the Post Template block (https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/post-template/index.php) is rendered, I think you can use the “render_block” filter for your block type and derive the query context in a similar way this block does.