Skip to main content

WordPress: customizing the Jetpack Infinite Scroll Footer plugin module

WordPress 4.1 is now live! With the brand-new Twenty Fifteen theme widely adopted by many blog and websites, the Infinite Scroll Jetpack module is becoming more and more popular (if you don’t know what we’re talking about you can read here to know more about this neat plugin).

As you might already know, the Infinite Scroll module features a standard Footer with the blog name on its left side and the “Proudly powered by WordPress theme <nome del tema>” phrase on its right side. If you don’t like their content you can change it with few lines of code.

To change the contents of the right side you can simply add this custom Filter (if you don’t know what a Filter is or how to add it to your WP website read here):


In order to change the left side of the Infinite Footer a few more lines of code will be needed:

The above code is a bit more complex than the previous one. We’re still using a custom Filter, but we’ll use it to launch a custom function who will change the whole footer content.

If you don’t want to mess with your template source code and/or you don’t feel like adding custom Filters and functions to your template code you can obtain the same result with the following JavaScript function (requires jQuery): you can append it to the end of your page’s <head> block (Appearance -> Edit > header.php):


If you just want to hide the Infinite Footer all you need to do is to add the following css rule (Appearance -> Edit CSS > style.php):

Happy customization!

Adding custom Actions and Filters to your WordPress blog

One of the most interesting features of the WordPress platform is the Hook capability, which can be easily used to any developer in order to add new features to themes and plugin. There are two distinct types of Hooks: Actions and Filters.

For a complete guide to Hooks you can read the official documentation available through the WordPress Codex (be sure to check the Actions and Filters specific sections): in this post we’ll just say that Actions are general-purpose functions which can be triggered by the execution of some theme or plugin events, while Filters are functions accepting a source content and returning a result which will be used instead.

This is an example of a simple Action who can be used to send an e-mail to a predefined list of accounts whenever a new post is added to the blog:


This is an example of a Filter who will look for profanity into the text field of each post replacing them with the #?*! string:


Now that we know what Action e Filter are, we can see how we can add them to our WordPress site or blog.

The easiest (and fastest) way is to simply append them to the functions.php file of the currently installed theme: this task can be easily done by using the WordPress Administration panel (Appearance -> Theme -> Editor). It’s as simple as opening the file using the WordPress editing interface and add the code of the desired Action or Filter after everything else. Despite its simplicity, this isn’t always the best thing to do: any Action or Filter added this way will be lost as soon as you upgrade the installed theme.

That’s why we suggest to adopt a more effective mechanism using an Hook management plugin like Add Actions and Filters, so you can insert your custom code in a separated container preserving it from theme changes and updates.

Add Actions and Filter Plugin - Screenshot


This is a screenshot of the aforementioned Add Actions and Filters plugin. Happy customization!

PHP & WinCache: a GUI to display statistics and usage info

If you installed WinCache on your web server (hopefully thanks to our previously posted guide) and you would like to know more about what’s happening behind the curtains, you can install this neat script to show all the WinCache caching mechanics & features fetched through their APIs.

The script it’s not made by us, in fact it’s used to be included in the WinCache official package (you can check if you already have it by taking a quick look at this page) but it’s existence is still unknown to most users: that’s why its usage is usually restricted to a limited set of privileged, knowledgeable guys: well, now you’re one of them!

Here’s a screenshot to show what it’s capable of:

WinCache Control Script

Not bad ad all, isn’t it?

IMPORTANT NOTICE: If your web server has Basic Authentication enabled, the script will prompt you for an Username and a Password: these are wincache / wincache by default, but can be easily changed by editing the first few lines of the script’s PHP code:

You can also disable the whole authentication part by setting USE_AUTHENTICATION to 0.


PHP: How to install WinCache on IIS to improve performances

The most crippling bottleneck for many PHP-based software is almost always related to memory consumption. The PHP command interpreter does an excellent job for any low-traffic website, but when your WordPress blog (or Joomla! commercial website) jumps out of the unknown and really starts to hit the mark, you can bet you will soon face the issue: pages becoming slower, requests hanging out and often reaching the 503 – Service Unavailable or other timeout errors, and other stuff that will drive crazy your monitor tools like Yslow (if you don’t use it yet, you better start now!), Analytics and so on

To drastically improve the performance of any high-traffic PHP website running under IIS you can consider installing one of the free caching PHP extension tools available: in this post we’ll cover the Microsoft one, namely WinCache, which is included in all the base PHP installation packages for Windows since version 5.2. This neat extension grants a serious performance boost thanks to a five-level caching mechanism:

  • OPCode Cache: Caches the compiled bytecode of the most used scripts, so the system can avoid to perform the same identical task multiple times.
  • File Cache: Caches the php files by loading them in a shared memory block, so they can be easily accessed by all processes avoiding expensive IO/file operations.
  • Resolve File Path Cache: Stores the mappings between relative and absolute file paths, thereby reducing the number of path resolutions that the PHP engine has to perform when it needs to calculate the absolute file path from its relative-to-current-folder reference.
  • User Cache: Stores any PHP objects and variables built for each user to reuse them for subsequent requests. This can be used to improve performance of PHP scripts and to share the data across multiple PHP processes.
  • Session Cache: Stores the PHP session data in the shared memory cache: this avoid file system operations for reading and writing session data, which improves performance when large amount of data is stored in PHP session.

Installing WinCache is fairly easy. The first thing you need to do is to check whether the php_wincache.dll file is included in your PHP installation or not. This file is located in the /ext/ subfolder of your PHP installation folder. If it’s not there, you can download it manually from the WinCache official website (just be sure to pick the file matching your PHP version), unpack it and copy the .dll file to the aforementioned folder.

Then you need to enable the WinCache extension to your PHP installation by adding the following two lines to your php.ini file, which is usually located in your PHP installation folder OR in the Windows root folder:

IMPORTANT: Before you do that you might want to check if the extension is already enabled by doing a quick text search for “php_wincache.dll” inside the file.

If you’re using PHP Manager for IIS (which you really should) you could also install the WinCache extension directly from the PHP Manager GUI.

If you’re NOT using PHP Manager for IIS and/or you have no idea of where your php.ini file actually is, you can easily track it by executing the phpinfo() command on your server (if you don’t know how, just click here to download a sample script, put it on your server and execute it): as soon as you did that you can review your whole PHP configuration, which contains the full path of the currently Loaded Configuration File:

Loaded Configuration File

That same phpinfo() command can be also used to check whether the WinCache extension has been properly installed or not. If that’s the case you will be able to see something like that by scrolling down a little:

Wincache configuration in PHPInfoIn most cases, like the screenshot above, the system will tell you that all the caches are currently disabled: this is perfectly normal, since we didn’t activate any of them yet.

In order to do so we need to add some additional configuration settings to our php.ini file:

These settings are generally OK for most production environments. You can fine-tune them by taking a look to the WinCache reference guide, where you will find a detailed description of any possible configuration setting to adapt WinCache to your needs.

When you think you’re done, save the php.ini file and restart IIS: you’ll be able to check the results of your hard work by executing the phpinfo() command again:

PHPINFO: wincache enabled

That’s about it: enjoy caching!

ASP.NET – MantainScrollPositionOnPostback for Chrome and most recent browsers

To keep (or to say it better, to recover) the page scrollbar position after a postback is definitely a feature any form-containing page should have. This used to be a trival task for any ASP.NET developer, who could just by add a simple configuration parameter to their code:

On web.config level:   <pages maintainScrollPositionOnPostBack="true" />

On page level:   <%@ Page MaintainScrollPositionOnPostback="true" %>

On code-behind level:  Page.MaintainScrollPositionOnPostBack = true;

Unfortunately all these methods, other than being unavailable with Razor, aren’t working anymore with any recent non-IE browser. Sure, it’s still possible to detect and configure the behavior of each one of them by using the ASP.NET Browser Definition Files accordingly, but in order to achieve better results it’s advised to adopt a centralized, versatile solution. Here’s a simple script based on the popular jQuery framework who does the trick in a cross-browser compatible way:

For WinForms:

For Razor (and also for any web page):

Needless to say, in order to make these scripts work you have to place the input element on top (asp:HiddenField for the WinForms one) inside the form element who will handle the Postback.

If you don’t like the standard HTML <input>  you can use the helper method equivalent provided by Razor, such as: