Loading template files in plugins

I’ve been working on a project where I wanted to include a template file to handle the display of a particular WordPress custom post type. However, I wanted this template to be included in the plugin that created the custom post type and not in the theme. The plugin adds the post type to one site, and one site only, within a multisite network, so I didn’t want to clutter up the folder of the theme which is used on other sites that don’t require the plugin.

So I looked for a way to do this and discovered the role of template loaders within plugins. Including a template loader in your plugin allows you to associate a template file in your plugins folder with a filter hook or a shortcode. But the great advantage is that it replicates the behaviour of the get_template_part() function — which means you can override the default plugin template file with a custom file in a child or parent theme. (Obviously I didn’t need this in this case but it is an example of the good practice of ensuring that plugins and themes are not dependent on each other.)

For a better explanation of this see Template File Loaders in Plugins.

As suggested in the above post I made use of the Gamajo Template Loader which is:

A class to copy into your WordPress plugin, to allow loading template parts with fallback through the child theme > parent theme > plugin

I found this class really easy to implement and you can download it from GitHub.

Thanks to Gary Jones the developer who made it available.

WordPress 4.0

The latest version of WordPress was released in September 2014. Today, being a little tardy, I’ve finished upgrading all Grit & Oyster maintained and hosted websites to the new 4.0 version.

Perhaps surprisingly for .0 release there aren’t that many new features to shout about. Instead it focuses on a number of solid improvements to the admin user interface.

For more info on the changes see the accompanying release video:

Video: Hosting and Building a WordPress Website

This is a series of videos that take you through the basic steps of hosting and building a website using WordPress. It is a useful guide to choosing a hosting solution and describes what you need to do to get a WordPress website set up using ‘one-click-install’ on a shared host (the most common approach for those switching to WordPress for the first time).

The videos are provided by WPMU DEV.

Backup Plugins for WordPress

As part of making sure the various installations of WordPress that I look after are working as they should I have been trying out various backup plugins. Everyone knows that taking regular backups is important, but almost everyone either forgets to do it from time to time or doesn’t do it regularly enough. So I was looking for plugins that would automate and simplify the process as much as possible.

The two I’ve chosen to use are:

BackUpWordPress

This is a really simple solution. It requires very little configuration to get up and running and is ideal for the beginner who wants a straightforward method for ensuring that their site is backed up regularly.

I’m using this on single site installations and will include it as the default backup plugin when I set up sites for clients.

BackWPup

For my multi-site installations I needed something a bit more sophisticated with a greater level of configuration. This plugin supports multi-site although in this situation it restricts access to the plugin to the network admin — but this is the kind of set up I was looking for. It has an annoying habit when first installed of adding a button to the WP admin bar, although this can be removed by selecting an option in the settings.

 

Dashes in WordPress

Here is a little note about dashes and hyphens and how WordPress handles them.

WordPress can do some clever things with typography — and some of these it does as standard. Look, it’s just done one of them in the previous sentence.  I typed two hyphens (or minus signs) into the editor and WordPress has automatically converted that into an em-dash. WordPress will also change a hyphen into en-dash when used in the correct place.

Not only does this make the text read better, and satisfy the small but passionate group of people who really care about these things, it is also really useful when writing posts in plain text or markdown. So here is a little reference of what to type to get different dashes:

Hyphen

one--two

= one–two

one - two

= one – two

En-dash

one-two

= one-two

Em-dash

one -- two

= one — two

More about this can be found in this post by Mark Jaquith from June 2012.

Genericons: a free icon font

I was looking the other day for an icon to indicate a drop down navigation menu in a mobile layout. I wanted something that would be easy to implement, flexible, and relatively lightweight. I decided that I would do it using an icon font, but that meant finding a font to use.

I chose Genericons – and was so impressed with it that I decided to permanently integrate it into ‘Oystershell’ my WordPress starter theme so that it will be easily available for use in future projects.

Some example icons from the font.

It has been released by Automattic so it has a number of features that are really handy for WordPress users. This includes these icons designed to indicate each of the native WordPress post formats.

Managing WordPress from your iPhone and iPad: The basics

WordPress for iOSThe other weekend I noticed in my Twitter stream that someone I follow, an experienced blogger, was having trouble updating their website using their iPad. This was until another friendly soul told them about the dedicated WordPress app that is available for that purpose. Suddenly they became much more productive.

I’ve learnt a few tricks and tips about blogging on the go using such devices but, based on that insight, I thought it would be useful to write about the basic steps that you can take.

Posting new articles to a WordPress website using the web browser on your iPhone or iPad can be difficult. While you can manage many aspects of your site by logging into the admin as usual the user interface isn’t really designed for use with a touch screen and you will find some tasks difficult to do.

A far better alternative is to download the dedicated WordPress app for iPad and iPhone and use that to access your site. Within this app you can edit and add new posts. You can also add and edit pages as well as moderate comments.

When creating new posts I tend to use other writing apps to compose my text and then paste that into the WordPress app to upload and publish it. But you can write posts directly into the WordPress app if you want.

To get started download the app from the Apple App Store. When you’ve opened it select “Add a Blog” from the settings and choose “Add Self-Hosted Blog”. Add the full web address of your site, your username, and your password. Then save. You should now be able to access the content of your site from within the app.

The WordPress app is free – but if you are prepared to spend a little money – there are a number of other blogging apps which should also be able to connect to your WordPress site. One popular one that I have used is Blogsy which is available for £2.99 from the App Store.

Not an Apple devotee? My apologies that this post is Apple centric. That is what I have experience of using. But I know that users of Android devices can also update their WordPress site on the go by using the android version of the WordPress app.

Note that if you have previously tried to use the WordPress or similar app to edit your site and had difficulties because of “XML–RPC support” this should no longer be an issue. You used to have to go and make sure that this was switched on in your settings. However, since WordPress 3.5 this support has been enabled as standard.