Month: May 2015

Choose different header images on different posts

Together with the WordPress Customizer a nice feature was introduced into WordPress: The header image. If a theme supports header images with add_theme_support() you can choose an image, which will be displayed in the header. I’ve read now an interesting question in a forum:

Can someone please tell me if it is possible to alter the header image in the theme Twenty Eleven (2.1) for every page?

I liked this question and thought to myself, there must be a nice filter function, you could use for this. So I started my search. The image gets output by get_header_image(), which can be found in wp-includes/theme.php. Of course, this function is using get_theme_mod(), which is located in the same file. get_theme_mod() expects the name of the mod as a parameter, in our case “header_image”.

Before get_theme_mod() outputs its result, the function filters it with the filter “theme_mod_{name}”. For the image, which is displayed in the header, the filter would be called “theme_mod_header_image”. Basically we are done here. We write a small function which filters our header image. In a first step the function checks with is_singular() if we are on a single page or post. If that’s the case, we check if the current page has the custom field “current-background”. If this field contains a valid URL, this URL will be returned. In every other case, our filter will return the standard header image, which the administrator defined in the Customizer:

Add additional links on the plugins overview page – part 2

A few days ago I already published an article on how to add additional links on the plugins overview page. Yesterday I run again into the plugin “Cleaner Plugin Installer” and saw, David adds for his plugin also links under the plugin description:

Cleaner Plugin Installer with additional links under the description
Under the description of David Deckers plugin are a lot of links.

Usually you just find the version number, a link to the authors webpage and a link to the plugins info. As you can see, the author also placed a link to the FAQ, the support and some other pages.

How did he do this? This line is filtered by plugin_row_meta. The single elements of this line are passed to filter as an array. In contrast to the filter plugin_action_links, which needs to be adjusted to the own plugin this filter is more general. This means: Since we just want to alter the line for our plugin, we have to check, if the current execution of the filter is for our plugin or for another plugin. As a second parameter the name of the plugin file is passed to the filter. So we can use plugin_basename( __FILE__ ) to check, whether our plugin line is filtered right now or another.

To add another element to this line, the code could be something like the following:

Sick of Google Analytics? Try the WordPress plugin Statify!

Still Google Analytics is the top dog when it comes to webstatistics. But there are numerous reasons, why someone doesn’t want to use Analytics. Privacy is just one issue, why people don’t want to work with Analytics no more. There are numerous alternatives out there. Today, I want to introduce you to Statify by Sergej Müller.

Especially when you worry about privacy, you should have a look as Statisfy is a transparent solution which doesn’t rely on third parties and doesn’t use cookies or the IP addresses of the visitors to track them down.

In direct comparison to statistics services such as Google Analytics, WordPress.com Stats and Piwik Statify doesn’t process and store personal data as e.g. IP addresses – Statify counts site views, not visitors.

You can also define how long you want the data to be stored and the additional database is rather lucid containing only four columns.

Also the plugin is quite lightweight, it gives you, what you need. A clean and beautiful insight over your visitors:

Visitor statistics with Statisfy
Visitor statistics with Statisfy

Statisfy is currently running on over 20,000 installs and received quite good reviews like this one, which points out the main advantages:

The strength of Statify lies in it’s simplicity. Set up with two mouse clicks you get a little widget in your dashboard that shows a chart with your website’s latest web traffic, the referrers plus the most active pages of your site – just enough data to give you a little feedback on the popularity of your site. As this information isn’t shared with third party, the plugin also meets German laws for the protection of your users privacy.

Another advantage is the good support which Sergej Müller is usually able to deliver. I saw it myself on Google+ how he quickly solved a server related issue in between minutes. Can you get this with GA? I switched today! What about you?

Add additional links on the plugins overview page

You know the usual plugin overview page. You have a small description of the plugins, the version, the author, a link to the plugins page and so on. On the left side, you will find the activation and deactivation links as well as the edit links. But from time to time, you will find plugins, which added a settings link or something similar to this line.

This is sometimes useful. Especially for plugins which do not need a lot of attention an additional list point in the admin menu is rather disturbing. In such a case a settings link on the plugin overview page is rather useful. But, how do you add such a link?

I searched a bit, how such plugins add these links and I found the filter hook “plugin_action_links“. This filter contains an array of all action links, which are shown on the overview page. Since these links differ from plugin to plugin, you have to adjust the filter for your own plugin by extending the filter name with the basename of your plugin:

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'function_to_execute' );

This filter function accepts now the array of links and you can alter the links as you wish. In my example code, I add a link to my web page:

But how to create a admin page which doesn’t appear in the menue? You can use add_submenu_page() and define the parent slug as ‘null’:

add_submenu_page( null, 'Title', 'Title', 'manage_options', 'invisible', 'render_function' );

This page can be reached via the URL wp-admin/?page=invisible, so by simply adding the GET-Parameter page with the page slug.