- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi All,
I am trying to replace one particular text (string) using gettext hook. I tried the following function which I added in my site’s functions.php
file.
function change_project_demo($text) {
$text = str_ireplace('project', 'demo', $text);
return $text;
}
add_filter('gettext', 'change_project_demo');
And it works fine as it replaces all instances of Project with Demo. But the problem is it also replaces Projects to Demos and Projection to Demotion
I just want only the text Project to change to Demo.
I also tried to use preg_replace
but probably I did not get the right syntax. In short, it’s not working for me and I do not see any resources online to get an answer to this.
Any help will be really appreciative.
Hello,
The following function should work fine:
function project_to_demo($text)
{
return preg_replace('/project\b/', 'demo', $text);
}
If you have any questions feel free to ask!
This is just Awesome Tom. Such a dumb I feel myself now.. thank you very much for your time and support. Will love to contribute to this forum myself sometime in the future.
Thanks once again.
:)