Forums › Forums › Search & Filter Pro › Search from external page and scroll to anchor
- This topic has 4 replies, 3 voices, and was last updated 4 years ago by Ross.
-
Anonymous(Private) October 23, 2020 at 12:30 pm #263840
Hi
I have a search on a different page then my results. When the search redirects you to the results page it should also scroll to an anchor link.
The search is on this page http://ranobo.fluxwebdesign7.be/product/amandelen-bruin/ and should redirect to http://ranobo.fluxwebdesign7.be/assortiment/?_sf_s=amandelen#producten for example.
So the question is if it is possible to add the anchor link (#producten) after the search url?
Thanks
Trevor(Private) October 23, 2020 at 3:32 pm #263872You can probably do that using this filter:
https://searchandfilter.com/documentation/action-filter-reference/#modify-urls
Anonymous(Private) October 26, 2020 at 10:44 am #264091Hi
Thanks for the answer. When I add the anchor after the url it still comes before the filter part of the url.
I have this code in my functions.php
function filter_function_name( $url, $sfid ) { if ( $sfid == 1019 ) { return $url . '#producten'; } } add_filter( 'sf_results_url', 'filter_function_name', 10, 2 );
and this returns http://ranobo.fluxwebdesign7.be/assortiment/#producten?_sf_s=amandelen when I search but I need it to return http://ranobo.fluxwebdesign7.be/assortiment/?_sf_s=amandelen#producten.
Is this possible?
Thanks
Ross Moderator(Private) October 26, 2020 at 7:37 pm #264190Hi Stijn
I’m afraid using that filter won’t work, because it will grab the URL, and put all the filtering at the end of it.
Right now there is no easy way… I think the best bet would be to add a custom attributes to your url using that filter, eg:
return add_query_arg( 'goto', 'producten', $url );
Then, on
template_redirect
– https://developer.wordpress.org/reference/hooks/template_redirect/Check if you have
$_GET['goto'] === 'producten'
andwp_redirect
to your desired URL (probably the current URL, without thegoto
and add the#producten
yourself – this is probably quite tricky to make, not even sure you can put a hash inwp_redirect
)…That I think is the best bet, not a great solution I think….
Best
-
AuthorPosts