Redirect www to non-www with .htaccess file

It occurred to me that just maybe you don’t want to display your site with the www subdomain prefix. In that case you could deploy the following code in your .htaccess file to redirect www to non-www. By doing so, users will access your site at not


If your website is hosted on an apache server, a redirect from www to non-www is a simple implementation. Add the following to your .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*)$1 [R=301,L]

Add the above code to you .htaccess file and replace with your domain name.

This post is a follow-up to a similar adrticle on how to redirect non-www to www with .htaccess.

How To: PHP to Display Current Year

An alternative method to using jQuery to display the current year would be to get the date server side with a language like PHP. If your web hosting can run PHP you can deploy the following PHP code to display the current year.

<?php echo date('Y'); ?>

Printing the current year on the page with a PHP script is commonly used to display a copyright year in the footer.

Current year isn’t the only format the PHP date() can display. Visit the date function page on to see the other formatting parameters.

WordPress Featured Images With an Auto Width or Height

To display the featured image of a WordPress post you would use the following:

<? if ( has_post_thumbnail() ) the_post_thumbnail(); ?>

Within the the_post_thumbnail() method you can include arguments that allow for further customization of the featured image in WordPress – also referred to as post thumbnail.

One such argument documented in the WordPress Codex is defining the size. The thumbnail size can be defined in the following ways:

the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)
the_post_thumbnail('full');            // Full resolution (original size uploaded)

the_post_thumbnail( array(100,100) );  // Other resolutions

When using the string (i.e. ‘medium’) to define the size, WordPress will use the settings from your setup to define the image size. Your image size settings are configured in Settings > Media. One item to note is the image sizes are created at the time the image is uploaded. So if you change you media settings after you have uploaded images, they will not apply retroactively to the images that were previously uploaded.

The last example from above, “the_post_thumbnail( array(100,100) );”, allows you to define a specific width and height to that implementation of the_post_thumbnail(). The numeric values are defined width, height like -> array(width,height)

How do I use automatic width or height for the featured image?

If you are working with a responsive design or fluid layout, you may need to use ‘auto’ to define the width or height. To do so, you can pass the ‘auto’ string in place of the width of height of the size array.

<? if ( has_post_thumbnail() )  the_post_thumbnail( array(400,'auto') ); ?>

Remember that the ‘auto’ is a string, so the single tick (‘) needs to surround the ‘auto’ string.

More details on the featured image customization options can be found at the WordPress Codex for the_post_thumbnail.