WordPress, its themes and plugins all come with default or custom strings of text, ‘Read more’ for example. At some stage, as a site owner or developer, you will inevitably want to change the wording in one of these text strings and there are a few ways to tackle the task.
We recently had a customer who requested that we changed the message shown when no results were found for a search term on their site. The site uses the standard WordPress search function and a reasonably simple theme, but the no results text string very definitely wasn’t the standard string used by the WordPress search function – ‘No results. Try again, would you kindly?’. So where was the string we needed to change and how could we change it simply, without messing with theme or core WordPress files?
First job: Find where the text string is … Open every single php file in WordPress, the theme and the plugins and manually check down through the code? Not very time-efficient! Open phpMyAdmin and do a search in the database tables? Only possible if you have access to phpMyAdmin, the database login details and are comfortable with what you’re doing because the potential for breaking the site is very high. I could go on, there are numerous possibilites.
The answer to the problem for us was the ‘String Locator‘ plugin. Once installed and enabled, you simply choose which files you want to search through (the entire WordPress directory, or just the themes or plugins), enter the text you want to find and then off it goes. When it’s done, you are presented with a list of the files in which text string appears. In our case, the string appeared in the theme’s index.php file and a couple of files for language translation.
Second job: So, we now needed to somehow change that text string in the index.php file. Easiest would be to simply edit the file. But that would be over-written when the theme gets updated. We could create a child theme and edit and save the php file there, but index.php is the main theme file and if we update the theme then our child theme version may well break things in future. These two options and various other code-change solutions were considered, but the fact that the string was found in translation files means that we could use a simple solution … use a translate plugin, which avoids the need to alter wordpress core, theme or plugin files.
‘Say What?‘ is a simple to use plugin that allows you to replace one string of text with another – that can be into a totally different language or just different words, whatever you enter. The only requirement is that the strings have been marked for translation, translated strings are generally wrapped in __(), _e(), or _x().
Install the plugin, activate and head to Tools > Text Changes. Click Add New and you’re presented with 4 text fields to complete.
The top and bottom fields are obvious, what you want to replace and what you want to replace it with. The tricky field is the Text Domain; the plugin needs to know where to look for the text string. So now we need to dig a little into the line of code where the string was found in index.php:
In the code above you can see the text string and following that is the text domain that ‘Say What’ is asking for; ‘hemingway’ … which in this case is the name of the theme, if the string is elsewhere, the text domain will be something other than the theme name. Note that the variables are wrapped in _e(), which means the content can be translated.
Back to the ‘Say What’ settings, enter the text domain.
Click the Update button. Test. Job done – we’ve changed a text string, without altering any files and the change will remain in place after any theme, plugin or WordPress updates.
Hopefully that’s helped one or two of you, feel free to comment below. Give us a shout if you need any WordPress help or custom work, we’re ready and waiting.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-advertisement | 1 year | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Advertisement". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
laravel_session | laravel uses laravel_session to identify a session instance for a user, this can be changed | |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
XSRF-TOKEN | 2 hours | The cookie is set by Wix website building platform on Wix website. The cookie is used for security purposes. |
__cfduid | 1 month | The cookie is used by cdn services like CloudFare to identify individual clients behind a shared IP address and apply security settings on a per-client basis. It does not correspond to any user ID in the web application and does not store any personally identifiable information. |
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Cookie | Duration | Description |
---|---|---|
YSC | session | This cookies is set by Youtube and is used to track the views of embedded videos. |
_gat | 1 minute | This cookies is installed by Google Universal Analytics to throttle the request rate to limit the colllection of data on high traffic sites. |
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Cookie | Duration | Description |
---|---|---|
_ga | 2 years | This cookie is installed by Google Analytics. The cookie is used to calculate visitor, session, campaign data and keep track of site usage for the site's analytics report. The cookies store information anonymously and assign a randomly generated number to identify unique visitors. |
_gid | 1 day | This cookie is installed by Google Analytics. The cookie is used to store information of how visitors use a website and helps in creating an analytics report of how the website is doing. The data collected including the number visitors, the source where they have come from, and the pages visted in an anonymous form. |
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Cookie | Duration | Description |
---|---|---|
IDE | 1 year 24 days | Used by Google DoubleClick and stores information about how the user uses the website and any other advertisement before visiting the website. This is used to present users with ads that are relevant to them according to the user profile. |
test_cookie | 15 minutes | This cookie is set by doubleclick.net. The purpose of the cookie is to determine if the user's browser supports cookies. |
VISITOR_INFO1_LIVE | 5 months 27 days | This cookie is set by Youtube. Used to track the information of the embedded YouTube videos on a website. |
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
Cookie | Duration | Description |
---|---|---|
CONSENT | 16 years 9 months 6 days 9 hours 9 minutes | No description |