Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search block submission URL can't be customized #35572

Open
iandunn opened this issue Oct 13, 2021 · 1 comment
Open

Search block submission URL can't be customized #35572

iandunn opened this issue Oct 13, 2021 · 1 comment
Labels
[Block] Search Affects the Search Block - used to display a search field [Type] Enhancement A suggestion for improvement.

Comments

@iandunn
Copy link
Member

iandunn commented Oct 13, 2021

What problem does this address?

The search block always submits to home_url( '/' ), but I'd like to submit to a custom URL.

In my use case, I'm building a header that will be used across all sites in a Multisite network. I want searches to go to a custom page that searches across all of the sites (example).

I want to preserve the ability to search a single site, though, so I'm not overriding WP's normal search behavior.

render_block_core_search() doesn't provide any filters or block attributes that can be used to change the form's action, though.

Related: #35260, #22071

What is your proposed solution?

I thought of two options:

  1. Add a block attribute. This would allow customizing the URL on a per-block basis. It seems like more of a dev/FSE feature, though, so it might not need a UI.
    <!-- wp:search {"formActionUrl":"https://wordpress.org/search/do-search.php" ... /-->
  2. Add a filter to render_block_core_search()
    add_filter( 'search_block_action_url', function( $url ) {
        return 'https://wordpress.org/search/do-search.php';
    }

I'd lean towards the attribute, but don't feel strongly. They're not mutually exclusive, either.

@skorasaurus skorasaurus added [Block] Search Affects the Search Block - used to display a search field [Type] Enhancement A suggestion for improvement. labels Oct 19, 2021
@iandunn
Copy link
Member Author

iandunn commented Feb 14, 2022

WordPress/wporg-mu-plugins#155 has a workaround, which is conceptually similar to solution #2 above.

A block attribute might still be nice, but maybe it's enough of an edge case that the workaround is good enough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Search Affects the Search Block - used to display a search field [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants