Rickmakeitquick
Rickmakeitquick

Reputation: 112

How to find Gutenberg block code and call it from template parts

I am trying to include a Gutenberg block - the Search widget - within a template part, so I thought looking at the code within the post_content field of the wp_posts table might help:

<!-- wp:search {"label":"","placeholder":"Search...","width":100,"widthUnit":"%","buttonText":"Search","buttonPosition":"button-inside","buttonUseIcon":true,"className":""} /-->

But I don't really know how to find the code or php file this refers to.

How can I use it to add that Gutenberg block into the php code of the template part site-nav.php, so the search box is part of the main menu?

Upvotes: 0

Views: 874

Answers (1)

Phil
Phil

Reputation: 1929

You don't need to use a Gutenberg block to show a search field in your template code. You can use the get_search_form() function directly in your PHP. That is the same function used by the search widget in WordPress.

Upvotes: 1

Related Questions