How to create an AJAX call in WordPress step by step

WordPress essentially works thanks to PHP language that gets the requests from users and admins, processes these requests and finally constructs the results as HTML pages, ie, PHP sends to you the pages that you see in the browser. Request, process, results; it’s simple. Sometimes however, you need control some elements of the screen after the HTML page has been sent and displayed: a special message on the screen after a checkbox has been checked, the change of an image depending on a select field, etc. and you don’t want to make a new request again. You want that these little elements change on the screen without repeat the whole process of request, process, results… In these cases you need to use the AJAX technique.

The first historical reference to AJAX technique (Roman Villa at Halicarnassus, 4th century AD)

Beyond this more than dubious historical reference of the previous illustration 🙂 , AJAX is a technology of developement supported by javascript and designed precisely for doing these kind of tasks, ie, to comunicate the client site to the server side silently, without a complete requests, just with the execution of a concrete funcion or module on the server side with a few concrete results. Continue reading…

Plugin reCAPTCHA in WP comments form plugin

reCAPTCHA in WP comments form plugin is an ANTISPAM tool that adds a Google reCAPTCHA field inside the comments form of your WP theme when the user is not logged in preventing fraudulent or deceptive comments.

The plugin also introduces a second verification process that detects the unauthorized direct accesses by spam robots to the WP comments system and allows you to decide what you want to do with those comments.

Finally, the plugin has got an optional forced javascript output mode that lets you to add a reCAPTCHA field also in old WP themes that didn’t use the new WP form comments functions but they make a direct output of its own comments form.

 See plugin details »

How to detect when get_template_part() WordPress function fails

Nowadays, in most of modern WordPress themes, the function get_template_part() is one of their essential elements. It just takes review the structure of, for example the last official themes (…, Fourteen, Fifteen, Sixteen), to realize that WordPress themes have evolved, from a structure quite monolitic to a structure driven by content and formats. And one of the keys to this evolution is the get_template_part () function.

silent diversity

get_template_part() it’s actually an invaluable element of any modern WordPress theme that through its two parameters allows us to select dynamically what .php file (what part) is going to be loaded for displaying the current page (see the official documentation for further information) however, one of its characteristics is that Continue reading…

Selective enqueueing of WordPress scripts and styles through conditional loading

Both in front and back end, WordPress themes and plugins usually enqueue styles and scripts; the real cornerstone of the our work. Security systems, communications, silent or programmed operations, intelligent data process… Most of these common operations have in their backgrounds the loading of scripts and styles. Today we’re going to see how design a selective loading of these components.

Big, big tires

Habitually, the loading of scripts and styles is made by themes and plugins through the functions.php and the /root-plugin-folder/plugin-name.php files respectively. In both cases, usually there is (are) a little function in these php files that programmes the loading of all of these essential components. Continue reading…

Using Post Formats with your custom WordPress Post Types

Since versión 3.1, WordPress introduced a new theme feature called Post Formats that, basically, allows us to divide a regular WordPress Post Type in subsets based on the nature of the information that a post includes, ie, you can have regular posts, but you can also have posts that specifically contain a video, or an image, etc. In case of the Post Type post, most of the popular WP themes already includes support for styling its Post Formats but, what can we do for using Post Formats in case of our custom Post Types?

macarons

The proposed method is quite easy and it simply extends the habitually used technic for dealing with Post Formats inside WordPress templates, in other words, we’ll create a refined system for loading the content-{$post_format_slug}.php subtemplates. Continue reading…

Strategies for URL redirection in WordPress front-end pages

I know that is not a common situation but sometimes it’s necessary to redirect the current page to another URL. Inside WordPress back-end is relatively simple but from the WordPress front-end templates that shows the Posts, Pages… It’s a little more complicated.

Change direction

In this article we’ll see some strategies for redirecting the URLs, all of them based in using the WP function template_redirectContinue reading…

Your plugins ready for WordPress PolyGlots

Perhaps, you are writing a new WordPress plugin and perhaps, you do want to translate it… If this is your case, there are two approaches: to translate the code via a code translator programme, for example PoEdit, or to use the translations WordPress system called PolyGlots.

Close up of the Rosetta Stone replica

In the first case –translating via an external programme– you just follow the general i18n WordPress developement recomendations for local languages but, if you have choosen WordPress PolyGlots plataform then, in addition to the general i18n rules, you have to do some little changes in the code of your plugin. In fact, there are not a lot of changes to do, just a few ones. Continue reading…

How to show all post types in Front Page results

Every day more websites use the Post Types extension of WordPress. They are not publishing just (simple) posts but they publish recipes, people profiles, city reviews, testimonials, or whatever you could imagine. It’s fantastic to be able to works easily with all these kinks of different information both in Front End and Back End however, when you access to your Front Page these Post Types aren’t shown in the results list of the main query. Are they shy? What can we do?

Army Photography Contest - 2007 - FMWRC - Arts and Crafts - A Plumpish Proportion

This behaviour is because of the relationship between the kind of executed WP query and the URL that you are typing in your browser. When you register a new Post Type inside your themes or plugins, WordPress automatically creates a new Continue reading…

Social Menus with Genericons

As a tiny module that follows WordPress very closely –it was included in the Twenty Fifteen Theme for example–, but not as a part of the official WP core, Genericons is an icon font very useful if you are thinking in creating a Social Menu. Well, this font includes a lot of good icons for other tasks but a third part of its icons are designed for giving support to social extensions.

Social Menus with Genericons

Using Genericons, to create a social menu for example similar as the installed in this web site, it is so simple as enqueueing the Genericons Font, creating a new WP menu and deciding which social profiles you desire to include. You don’t need to add a special code, or modify substantially your themes 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…