Frontend Text Strings

WordPress has a unique system for translating WordPress into different languages and this gets carried through to plugins and themes, as well, assuming they’re compatible. If you’re a WordPress developer, you’re probably already familiar with process of localization.

However, you also probably know that the process of localization isn’t the easiest thing to accomplish and can be a bit of a pain if you’re just looking to do a simple translation of some elements on the frontend of your website, opposed to needing to translate every piece of text used by the theme throughout the WordPress admin.

The Theme Blvd framework takes this into account and provides you with a simplified alternative to localization. Basically we’ve organized things, so that all the text strings appearing on the frontend of the theme, come from a centralized array with a filter applied.

Note: You can also use this filter if you’re just looking to change the wording of a particular text string. This doesn’t need to be exclusively for translation.

How It Works

If you’re going through framework files, you’ll probably come across a function called themeblvd_get_local here and there. This is what’s used to pull a the filtered result for each text string. Each time this function is used, an ID is passed on for the particular text string being retrieved.

If you follow the rabbit hole down to the source of where these text string come from, you can find them all setup alphabetically in a filterable array at /framework/includes/locals.php, something like the following.

function themeblvd_get_all_locals() {

	$locals = array (
		'404'						=> __('Apologies, but the page you\'re looking for can\'t be found.', 'jumpstart'),
		'404_title'					=> __('404 Error', 'jumpstart'),
		'all'						=> __('All', 'jumpstart'),
		'archive_no_posts'			=> __('Apologies, but there are no posts to display.', 'jumpstart'),
		'archive'					=> __('Archive', 'jumpstart'),
        // etc ...
    );

    return apply_filters('themeblvd_frontend_locals', $locals);
}
Note: If you’re using a theme with framework 2.2-2.4, these text strings are located in /framework/api/locals.php.

Now, you can see at the bottom a filter is applied called themeblvd_frontend_locals, that you can utilize to change any of the items.

How to Modify Text Strings

If you understand the basics of working with filters, this should be fairly straight forward. Taking the following screenshot into account, let’s say we want to edit what shows on archive pages when no posts are found.

By opening up /framework/includes/locals.php we can see that the id archive_no_posts pulls a text a string that says, “Apologies, but there are no posts to display.” So, using our filter, we can modify this text string in the following way.

function my_locals( $locals ) {
	$locals['archive_no_posts'] = 'Your new text';
	return $locals;
}
add_filter('themeblvd_frontend_locals', 'my_locals');
Note: If you’re using a theme with framework 2.2-2.4, these text strings are located in /framework/api/locals.php.

And it’s just as easy to do multiple text strings, in the same way.

function my_locals( $locals ) {

	$locals['404'] = 'Your new text';
	$locals['404_title'] = 'Your new text';
	$locals['archive'] = 'Your new text';
	$locals['archive_no_posts'] = 'Your new text';

	return $locals;
}
add_filter('themeblvd_frontend_locals', 'my_locals');
Note: There is also a plugin available that you can use to accomplish this process of editing text strings: Theme Blvd String Swap.