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

Unable to fetch head metadata on search strategy when search keys has more than one word #537

Closed
1 task done
nicholasio opened this issue Jun 30, 2023 · 7 comments · Fixed by #663
Closed
1 task done
Assignees
Milestone

Comments

@nicholasio
Copy link
Member

nicholasio commented Jun 30, 2023

Describe the bug

There seem to be a few issues with the Yoast get_head endpoint that is not properly recognizing the requested page as a search page.

Steps to Reproduce

  1. Go To Search
  2. Search for two words
  3. Missing/wrong metatags or crash.

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nicholasio nicholasio changed the title Unable to fetch head metadata on search strategy when search keys has more than one work Unable to fetch head metadata on search strategy when search keys has more than one word Jun 30, 2023
@lucymtc
Copy link
Contributor

lucymtc commented Jul 4, 2023

@nicholasio I have also noticed an issue with get_head endpoint when appending the url param with
'${getWPUrl()}/?s=${params.search}
If the WP url returned by getWPUrl() has a trailing slash, this will add double slash to //?s= where get_head endpoint returns page not found.
I needed to do const wpUrl = getWPUrl().replace(/\/$/, ''); first to remove the trailing slash

@nicholasio
Copy link
Member Author

nicholasio commented Jul 5, 2023

Thanks @lucymtc Here are a few things I found:

  • Yoast is not properly detecting a search page via the get_head function.
  • Searching for multiple words crashes the get_head query and thus makes the framework default to the metadata of the first post returned.
  • Yoast also does not yoast_head to the WordPress search endpoint.

I'm not sure if we can rely on on Yoast to generate the meta tags for the search page.

@nicholasio nicholasio added this to the v1.1 milestone Jul 11, 2023
@nicholasio
Copy link
Member Author

Alternative solution: Have the SearchStrategy manually build the yoast_seo object and yoast_html fields manually with basica meta tags.

@lucymtc
Copy link
Contributor

lucymtc commented Jan 9, 2024

@nicholasio for the issue:

  • Searching for multiple words crashes the get_head query and thus makes the framework default to the metadata of the first post returned.

I found what the problem is and opened an Issue and PR in Yoast

I tried to override the validate callback for the URL, the way to do this would be to register a get_head endpoint from our side as if $override is set to false in register_rest_route WP merges with newer overriding if duplicate keys exist.
The problem is that you need to pass in the exact arguments that the original register_rest_route (the one in Yoast) is called with, and the callback function depends on an instance of \Yoast\WP\SEO\Routes\Indexables_Head_Route which has dependencies in other Yoast classes and doesn't make it straight forward to instantiate the class. Unless Yoast exposes an instance of the class but I haven't found anything so far.
I tested other hooks to try override the validation callback without success.

@lucymtc
Copy link
Contributor

lucymtc commented Jan 16, 2024

Update on fix for "Searching for multiple words crashes the get_head query and thus makes the framework default to the metadata of the first post returned." has been merged into Yoast via this PR Yoast/wordpress-seo#21032

@lucymtc
Copy link
Contributor

lucymtc commented Jan 19, 2024

Opened PR #663 for:
Yoast is not properly detecting a search page via the get_head function.
Yoast does not yoast_head to the WordPress search endpoint.

@nicholasio
Copy link
Member Author

Update on fix for "Searching for multiple words crashes the get_head query and thus makes the framework default to the metadata of the first post returned." has been merged into Yoast via this PR Yoast/wordpress-seo#21032

Looks like the PR merged will be released in Yoast 22.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants