Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Replace result-urls with something else › Reply To: Replace result-urls with something else
August 1, 2020 at 9:16 am
#28777
Keymaster
Hi Julius,
You are looking for this code snippet:
add_filter( 'asp_results', 'asp_custom_link_results', 10, 1 );
function asp_custom_link_results( $results ) {
// Parse through each result item
foreach ($results as $k=>$v) {
/**
* In this context the
* $results[$k]->link
* variable holds the result link. Make modifications to that variable.
*/
$results[$k]->link = 'https://google.com';
}
return $results;
}
I would recommend something like this:
add_filter( 'asp_results', 'asp_custom_link_results', 10, 1 );
function asp_custom_link_results( $results ) {
// Array of original -> replacement links
$replace = array(
'websiteurl1.com' => 'google.com',
'websiteurl2.com' => 'wikipedia.com'
);
// Parse through each result item
foreach ($results as $k=>&$r) {
/**
* In this context the
* $results[$k]->link
* variable holds the result link. Make modifications to that variable.
*/
$r->link = str_replace(array_keys($replace), array_values($replace), $r->link);
}
return $results;
}
Just enter the values to the $replace variable. On each line, the left side is the value to replace, with the value on the right side.