Enqueueing Google Fonts In WordPress Method Two

As we have already described how to enqueue the Google Fonts in your WordPress project through one method, now we will be enqueueing it via the translation ready way method.

Here, for the method of enqueue of Google Fonts in translation ready method, first of all what we have to do is to create the function for enqueueing the Google font as below:

Here in the above example, first of all, we have created an array in the variable $fonts_url, since we may add more than one Google fonts there for our project. Now, again $fonts variable is assigned as an array and we have provided $subsets value as latin,lation-ext, since this subsets is universal, ie, it is common in all of the Google fonts available.

Now, we will provide the translation method to enqueue the Google Fonts in your project. Here, what we have to do is, we need to check if the condition is true or not, as described in the translation file, which will be controlled by the first value used in _x() function. So, here if on is changed to off in the translation file, then, this enqueued Google font will not be loaded.

Now, again since there may be subset available for that chosen Google Fonts, so we also need to check those in the next step as above, which is done in just below the enqueue of Google font option. Now, finally, the enqueued Google font is ready to be used, and is now assigned to the variable $fonts. Now, the above process is completed. Now, to enqueue this font, we will have to create the function as before described here:

Enqueueing Google Fonts In WordPress Method One

But, here the change is that, we do not provide the url of the Google font as above described, we will provide the function name created above instead in it as below:

Now, by using this method, you can control about the need of the Google font subsets to be used in your site, since some of the language may need the subsets and other not. Here, below is the final code for enqueueing the Google font in your site:

We hope that, now you can enqueue the Google Fonts properly in your upcoming projects by using the method described above, if you are in success in following the tutorial and loading the required Google fonts in your project properly. But, if still you could not, then, do comment below in the comment box and we will follow it up.

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.