Hello,
I apologize for the inconvenience you are facing with the Sitelinks Searchbox Schema. To change the target URL parameter in the SearchAction schema, you can use a code snippet. Here’s an example of how you can modify it to include the post_type=product
parameter:
/**
* Filter to modify the SearchAction JSON-LD data
*/
add_filter( 'rank_math/json_ld/search_action_url_template', function( $url_template ) {
// Modify the URL template as needed
$url_template = 'http://www.yoursite.com/your-post-name/`';
return $url_template;
});
You can add this code snippet to your theme’s functions.php
file or the Rank Math custom code editor. After adding the code, remember to click the Update File button.
If you encounter any issues or need further assistance, please feel free to reach out to our support team directly here. We are here to help!
Thank you for bringing this to our attention.
Sources:
How to Add Sitelinks Searchbox Schema to All Pages » Rank Math
Analyzing Your Site’s SEO with Rank Math’s SEO Analysis Tool
How to Configure Sitemaps in Rank Math – Best Settings and Tips
General Tab in Meta Box of Rank Math SEO Plugin
Working With the News Sitemap in Rank Math » Rank Math
The snippet is not working. The url remains unchanged.
Hello,
Apologies for the inconvenience.
To change the search URL for Sitelinks Searchbox schema, please use this filter on your site instead:
/**
* Allows filtering of the search URL.
*
* @param string $search_url The search URL for this site with a <code>{search_term_string}</code> variable.
*/
add_filter( 'rank_math/json_ld/search_url', function( $url ) {
$url = 'https://yourwebsite.com/?s={search_term_string}&post_type=product';
return $url;
});
Please ensure to update the website in the code with your actual domain name.
Here’s a way to apply the filter on your site:
https://rankmath.com/kb/filters-hooks-api-developer/
Hope that helps.
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post or TrustPilot about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.