Using wp_add_inline_script function. A Google Analytics example.

Until version version 4.4, in WordPress, there was only one way to add script files to the WordPress themes, the function wp_enqueue_script however, the new version 4.5 has introduced a new way, the function wp_add_inline_script that allows us to add javascript text scripts directly inside a template and that, in addition, it can be directly connected with other scripts. Let’s go to see how it works.

Example of using the wp_add_inline_script function

At bottom, this new function wp_add_inline_script is the equivalent for scripts files, to the wp_add_inline_script function is for CSS files. Let’s see how it works through and example based on adding the Google Analytics script to a WP theme. Continue reading…

Configuring WordPress Automatic Background Updates

Automatic background WordPress updates were introduced in versión 3.7 and since then, this module has been maintaining your installation updated and ready for working however in some cases, you don’t desire that your WordPress installation changes without your permission. Perhaps for compatibility with a special developement addition, perhaps for some non updated but critical plugin or any other reason you do need to control manually the WordPress Updates. If this is your case then go ahead but rather it is much better to leave the maintenance module quiet.

Configuring WordPress Automatic Background Updates

As the official documentation explains about the Automatic Background Update Module, this module has 4 different Types of working. Continue reading…

Showing posts with different templates, the “single_template” filter

Habitualy, the WordPress template hierarchy for posts, uses a simple descendant decision tree for choosing which single_template.php file is going to be used for showing a single post. This decision tree is quite usefull so that, simply creating a .php file called like single, single-posttype, etc., it’s possible to control very accurately which template will be used for showing data.

Normal Decision Tree for Single Elements

However, in contrast of pages that each one can have its own template, ie, they have a very flexible decision rules, choosing the templates for posts is ruled by criterias more restrictive based in sets of elements Continue reading…

Marking all external links for opening in a new Tab Browser

Normally, it’s while you are writting a post, when you mark the links inside the text as normal or “for opening in a new Tab or Browser” –typically the external links–; simply you mark the checkbox Open link in a new Tab in the Links Tool of WordPress Editor but what does it happen if you have already got a lot of posts non marked, or if you have changed the criteria for external links, or whatever similar situation?

Food Camera and Backchannel: MIT Media Lab lists

Well, the long solution consists of editing all posts and to locate and to correct manually the external links but, if you have more than a hundred of posts with a lot of links probably, it will be an very stressing task, and surely, you’ll forget some of them… Continue reading…

How to move jQuery script to the Footer

As default, WordPress actions put the jQuery scripts in the header of all HTML pages however, sometimes it is necessary to move these scripts to the footer of the page but a simple movement is impossible. As jQuery script (and dependents) is defined by WordPress during the first steps of its loading, when you try to redefine later its output through wp_enqueue_script( ..., $in_footer TRUE ) or similars, you haven’t got any result.

Designing a new feature, with jQuery!

There are some methods to make this change, some more risky, others more conservatives. Today, I’m going to show two methods very simple and quite conservative based on Continue reading…

How to suppress the emoji module?

As the WordPress documentation says, Emoji are the ideograms or smileys (for example 🙂 ) used in electronic messages and Web pages. Originating in Japan on mobile devices, they are now commonly available on devices worldwide, ranging from mobile to desktop computers. Emoji are decorative, useful and they can actually make any website more friendly, maybe for this reason, the Emoji module is added as default by WordPress to all Themes but, what can we do if we don’t want to load this module?

Emoji keyboard example for Android by Kraftbj on WordPress

The WordPress Emoji module is independent of any theme, and just depends on two files (a little CSS code and a script) that are tipically added to the HTML <head> element. This addition is made through two functions Continue reading…

How to add the google-site-verification code or other API parameters to your WordPress themes

Webmasters Tools of Google is a set of useful utilities that allow you to control a lot of elements of your website and among them, specialy the reading of the list of your pages through the sitemap.xml file. It is really a fantastic tool for your SEO so I’m sure that you want to connect with it. For connecting your site with an specific Webmaster Tools account, google offers you several methods but, perhaps the easiest is the addition of an HTML meta tag in the HTML <head> of your pages containing the google-site-verification code. Today we’ll see a method for adding automatically this google-site-verification code in a theme and for extension, for adding any API codes, third party parameters, etc.

How to add the google-site-verification code or other API parameters to your WordPress themes

In fact, every day is more common to use APIs to access from your web to services offered by outside webs so I do really suppose you want to use easily the associated codes to all these APIs in your Themes. Continue reading…

How to order the Replies of the Comments

WordPress has a good interface for ordering and showing the comments of a post for the themes. You simply have to do click on the Admin’s menu Settings / Discussion and in the section Other comment settings, the last two lines offers you three fields for controlling it: number of comments for each page, which page is shown in first position (the last or the first) and, of course, the order of the comments (older or newer comments) for each comments page… But, what about the replies of each individual comment? How to control if these replies are displayed in ascending or descending order?

How to order the Replies of the Comments

Though in terms of data type, comments and replies are the same, due to their hierarchical structure,  Continue reading…

Loading a language translation in a Child Theme

When we need introduce some changes in the behaviour, features or style of the theme that we are using, Best practices in the WordPress environment advises us to never change the principal theme but writting a small child theme containing those modifications. In that case, when those modifications show text on the screen, of course we can opt for outputting directly this text but it’s usually better to use the translation functions. But then, How to read a child theme translation keeping the principal (parent) theme translation?

Loading a language translation in a Child Theme

The solution is very simple because in fact there are two different functions to do that. For reading the translation of the parent theme, we have to use the function called load_theme_textdomain however, for reading the translation of the child theme Continue reading…

How to modify the FavIcon links of the function wp_site_icon in WordPress?

Since version 4.3 WordPress introduces the ability to add a Icon automaticly to your site through the Customizer / Site Identity module. In fact this icon is known as the FavIcon and it is based in a very fuzzy and changing specification that, in addition, depends on the devices to what the favicon is prepared for, so WordPress developers team has logically opted for an very standard HTML output for favIcons. This standard HTML output works but perhaps you want to improve, extend or adapt it to other devices or programmes that are going to read it and use it. (See the next examples).

New Gmail favicon

favicons

Favicon for the Birdies 100 blog

There are several methods for changing this HTML FavIcon output and include improved sentences for its definition, ones more radicals, ones more WordPress code friendly, but in this example I’m going to propouse one method based on the conservative approaches so I’ll use a filter instead of redefine the list of actions attached Continue reading…