I have this code snippet :
$nieuwetitel = the_title();
echo str_replace('Bijenkorf', 'test', $nieuwetitel);
the_title()
outputs the following: Bijenkorf – Acne Studios Adriana €360
Using the code mentioned above, I would like to change 'Bijenkorf' to 'test', however this does not seem to work.
In the end I would like to create a list of things to exclude from the_title()
(Bijenkorf is one of them).
You can use the_title filter for this.
Here is the code.
function wh_alterProductTitle($title, $id = NULL)
{
//for only changing product title
if ('product' == get_post_type($id))
{
//for single
$title = str_replace('Bijenkorf', 'test', $title);
//for multiple
//$title = str_replace(['find1', 'find2'], 'test', $title);
}
return $title;
}
add_filter('the_title', 'wh_alterProductTitle', 10, 2);
Hope this helps!