Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I want to change meta description of search results page if there search query does not return any result, how I can do this?
Comments
Comment #1
DamienMcKennaYou would have to write some custom tokens that could (somehow) sniff the search results, and then add them to a per-path definition.
Comment #2
Sharique CreditAttribution: Sharique commentedPath is same so we cannot use per path definition.
We are using custom search search service. We created a panel page to for search which contains custom search form and results ctools content type. Results pane take parameters from query string, send request to services and render results, here I need to check results count and alter meta description.
Comment #3
Sharique CreditAttribution: Sharique commentedIf I can alter metatag context I can do that. Is there a way to alter context before getting hook_metatag_metatags_view_alter called?
Comment #4
DamienMcKennaThe by-path settings are just slightly customized Context definitions, and you could extend the by-path settings by using the main Context UI to add more conditions as needed - I believe there's a condition that will let you filter on the query string.
Comment #5
Sharique CreditAttribution: Sharique commentedWe cannot identify no of results returned by looking at query parameters. Hence we cannot by path settings.
Comment #6
DamienMcKennaI'm not sure there's really a good way of doing this using Drupal's internal Search module, there isn't an obvious way to find out how many results there are without trying e.g. hook_preprocess_page to customize the meta tags based on the output of the page's content.
Comment #7
DamienMcKennaAlso, I'm sorry for not getting the point of your problem until now, but now that I understand what you're trying to do I do see it being tricky to work out.