Yearly Archives: 2015

Apache: How to block all other IPs except for your own

Sometimes I have to work on WordPress sites that are too busy to display the admin interface. This can happen if there’s more traffic than the server can cope with. In such cases, we may need to tell every visitor to come back later while we carry out some maintenance.

But how? Thanks to an Apache command to block all IP addresses, except for our own. We can even display a “maintenance” page while we’re hard at work behind the scenes.

Let’s see how. Add the following to your .htaccess file in the web root directory, replacing 12.34.56.78 with your own IP address:

Save the file on the server and see the site speed up as of by magic. No more requests but your own shall be processed henceforth.

Thanks to MickeyRush and b101101011011011 for this solution on Stack Overflow:

How do I find my own IP?

There are several services that will display the IP you’re currently connecting from. Head over to http://whatsmyip.org, or type “my ip” into Google.

Does this work with NGINX too

I’m sure the principle does, but I know very little about NGINX configuration. The above directive is for Apache only. If you know how this works in NGINX, please leave a comment below.

How to move the sidebar to the right in TwentyFifteen

I’ve never liked themes with sidebars on the left – probably because we in the western world start reading on the left, and I’d like there to be as little clutter as possible. Or perhaps I’m used to navigation items on the right.

I was looking around for solutions to move the sidebar in Automattic’s TwentyFifteen theme to the right, and several options can be found on the internet. Here are two that worked for me:

Option 1: CSS Tweak

Thanks to the Stack Exchange community, this CSS tweak works a treat (for left-to-right languages):

Add these declarations to your own TwentyFifteen Child Theme and you’re good to go. If added via a CSS widget or to the bottom of the original theme (which is a really bad idea), additional “!important” statements may be necessary.

Kudos to toschero and Anteru for the combined solution to this puzzle. Check out the full discussion here:

Option 2: Pre-made Child Theme

Ruhul Amin from Tips and Tricks HQ has built a ready-to-use child theme and solved this puzzle in PHP. You can check it out here:

WordPress 111: Users, Roles and Capabilities

In this video I’ll show you the multi-user capabilities of WordPress: how to create new users, and what capabilities the different user roles have over your WordPress site.

This feature comes in handy if you collaborate with other users: each user can create posts, but such users can be restricted from deleting other people’s posts, or change the layout and functionality of the website.

You can watch the full course on one convenient YouTube Playlist.

Enjoy!

WordPress 110: URLs and Permalinks

In this episode I’ll explain how you can change the URLs for your posts and pages, as they appear in your web browser. By default, WordPress uses numeric links (such as domain.com?p=123) but those are not so easy on the eye.

We can change this to something like domain.com/awesome-post instead, and I’ll explain how to do it, as well as the implications of changing URLs retrospectively.

You can watch the full course on one convenient YouTube Playlist.

Enjoy!

How to prevent instant logout trouble with WP eMember

Screen Shot 2015-09-18 at 15.29.19

I’ve been having issues with the otherwise excellent WP eMember Plugin by Tips and Tricks HQ: while members are logged in, they are often logged out as soon as they click a link. Thankfully I’m not alone with this problem – and it’s easy to fix:

In the admin interface, head over to WP eMember – Settings and find the option Logout the Member After XX Minutes. When this setting is left blank or set to 0, the instant logouts happen. If the value is set to 360 (that’s 6 hours), logouts no longer appear to happen during a regular session – only after 6 hours.

Thanks to avd23 on the Tips and Tricks forum for this tip!

WordPress 109: Mysteries of the MORE Tag

In this episode I’ll show you how the MORE tag works. It’s a “break mark” you can use so that longer posts don’t take up too much space on your front page. I’m also explaining a related feature called the NEXTPAGE tag with which you can break even longer posts into individual pages.

You can watch the full course on one convenient YouTube Playlist.

Enjoy!

How to fix a “could not bind to address” error in Apache

I have worked on a server recently and I came across a problem (again) that I meant to write about, and include a solution should you suffer from a similar problem. It was a Plesk server running CentOS, but this particular issue can also happen on plain LAMP stacks.

Trying to start Apache, I got the following error message:

The port number may be different depending on which port Apache is supposed to listen on (80 is the default, but depending on your system it may be something different, for example 7080). What this error is saying is that the Apache config file says the service is supposed to use a specific port, and another service is already using it. Hence, Apache can’t start or restart.

If your server has worked fine before, then it’s likely that the config file is not the problem – so don’t go messing with it unless you absolutely know what to tweak.

Let’s find out what service (or process) is listening on our port. We can do this using the lost command:

Replace the port number (80 in the above example) with your own. In this example, Apache is in fact listening but something isn’t quite right and it’s unable to restart. We can go and kill each of these processes using the following command:

Do this with every process ID (PID) from the list you get from the lsof command. As soon as they’re all dead (verify with lsof), try to restart apache once again:

This has helped me on a number of occasions 😉

WordPress 108: Tags and Categories

In this episode I’ll show you how you can organise your posts with tags and categories. You don’t have to use tags, but a post is always in a default category (called “uncategorized” by default, and I’ll show you how to change that too).

The full course is aimed at beginners and medium casuals alike. Whether you’ve been away from WordPress for a while, or if you’re a complete newbie, this is a very un-intimidating “getting started” guide.

You can watch the full course on one convenient YouTube Playlist.

Enjoy!

WordPress 107: Embedding Videos

In this episode I’ll show you how to embed videos from YouTube and Vimeo into your posts and pages. This works with some magic called oEmbed, a technology that only requires the URL to the video, from which WordPress can determine the correct width for your theme and pull in the complicated code we once had to post.

This principle works for embedding other sources as well, for example images from Flickr, Tweets from Twitter and even Kickstarter campaigns.

The full course is aimed at beginners and medium casuals alike. Whether you’ve been away from WordPress for a while, or if you’re a complete newbie, this is a very un-intimidating “getting started” guide.

You can watch the full course on one convenient YouTube Playlist.

Enjoy!

WordPress 106: Working with Images

In this episode I’ll show you how with images in WordPress.

I’ll explain how to upload them, how to embed them into your posts and pages, and what happens behind the scenes when you do that. We’ll also discuss Featured Images, the relationship between the “image” and “embed code”, and we’ll talk about the actual image sizes on the server.

The full course is aimed at beginners and medium casuals alike. Whether you’ve been away from WordPress for a while, or if you’re a complete newbie, this is a very un-intimidating “getting started” guide.

You can watch the full course on one convenient YouTube Playlist.

Enjoy!