A specialist in WordPress and Content Management Systems for Business Websites and eCommerce Solutions.
Read more »
Check out my most recent project →
Here’s a quick and easy way to update image sizes on the fly directly in your Wordpress posts. Add this code into your functions.php file in your theme. Then make sure you insert timthumb.php in the root of your theme directory. Next create a fully writable directory named ‘cache’ and place that in your theme root directory.
Now inside your posts just wrap an image URL with the img shortcode. Add height, width, alt, and class to it for more flexibility.
1 2 3 4 5 6 7 8 9 10 11 12 | // Image resize in content // To Use: [img w=600 h=200 class=alignleft alt=My Photo]http://mysite.com/photo.jpg[/img] function timmyimg($atts, $content = null) { extract(shortcode_atts(array( 'w' => '600', 'h' => '250', 'class' => 'alignnone', 'alt' => '' ), $atts)); return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />"; } add_shortcode('img', 'timmyimg'); |
Occasionally you’ll need to fetch a posts image outside of the loop.
1 2 3 4 5 6 | <?php $thumb = get_post_meta($post->ID,'_thumbnail_id',false); $thumb = wp_get_attachment_image_src($thumb[0], false); $thumb = $thumb[0];?> <img src="<?php echo $thumb; ?>" alt="" /> |
Combine this with the Timthumb script for control over image size.
This will output the URL to an image with the size predefined by ‘post-thumbnail’ in your functions file when registering the functionality for post images.
1 2 3 4 5 | <?php $thumb = get_post_meta($post->ID,'_thumbnail_id',false); $thumb = wp_get_attachment_image_src($thumb[0], 'my-custom-size', false); $thumb = $thumb[0]; echo $thumb; ?> |
The above code is referencing ‘my-custom-size’, which we can see below as being 405×180. Typically it is not advised to use these predefined sizes as it will overload your uploads directory with additional sizes, and it puts strain on your server when uploading images. Better to use the above method with the Timthumb script to get an exact image size, while making use of image caching.
1 2 3 4 5 | if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9 add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 50, 50, true ); // Normal post thumbnails add_image_size( 'my-custom-size', 405, 180, true ); } |
It is a great idea to have a Facebook fan page for your company, club or organization.
This is a minor hack of the Fotobook plugin (Version 3.1.8) for WordPress by Aaron Harp. Fotobook is originally meant to apply your personal photo albums into WordPress, but we’re going to make one small code tweak to instead pull the albums from the fan page that we administer.
After installing the plugin, go ahead and activate it and grant the permissions to your Facebook account.
Next, visit your Facebook fan page, and click into an album so you’re viewing all photos in one particular album. In the address bar you’ll see a &id=123123123. Copy that ID number.

In the plugin directory open the fotobook.php file and head down to line 243 and look for this code.
$uid = $session['uid'];
Swap that code for this
//$uid = $session['uid'];
$uid = 123123123;
With the 123123123 being the ID code for your fan page.
If you have a custom URL set for your fan page you might notice that the album photos are not showing. To correct that move down around line 809 in fotobook.php and look for:
if(!is_numeric($id)) return false;
And code it out of use by adding // in front so that it now looks like
//if(!is_numeric($id)) return false;
Back in the plugin administration page, go ahead and import your albums. And you should be good to go!
With a thanks to B. Thibault in the forums at the Fotobook Application Page.
I recently noticed that a particular post had built up about 10 or 15 revisions for it. I started thinking that of all the posts I have, there have to be quite a few revisions and therefore are creating a hefty sized table in my database. This was run on my WP 2.8, but should work for 2.6 and up.
Here is a solution to prevent revisions from being created, as well as removing all revisions from your database.
Open wp-config.php and add this to the very bottom of the file, before the php closing tag.
define('WP_POST_REVISIONS', false);
This completely turns off any revision creation. If you’d like to restrict revision creation to a set amount per post, you can change ‘false’ for the number of revisions you’d like stored.
Open up your database in phpmyadmin and run this SQL Query.
DELETE FROM wp_posts WHERE post_type = "revision";
And now you’ll have a more tidy database.
In this tutorial, we’ll go through the process of setting up a server on your local computer. This will allow you to run PHP & MySQL applications, such as Wordpress, directly on your machine.
As I have yet resisted joining the ranks of the Mac cult, we’ll be using PC server software. I am aware of XAMPP, WAMP, and I personally use VertrigoServ for no other reason than it is the only one I’ve tried. (Mac cultists can use MAMP.)
They say that cleanliness is next to godliness, and in that vein let us install our server in a organized location. On my desktop, I actually use a whole separate hard drive to store my server. If you don’t have the luxury of a dedicated HDD, then your local disk or C:\ will be fine.
Create the following directory: C:\usr\. Then run the server installer, and be sure to install the software in the C:\usr\ location. If you installed the VertrigoServ software, then the “public web” files will be located in C:\usr\www\. So let’s download and install Wordpress inside C:\usr\www\wordpress\ and then be sure to fire the server up after installation.
So we’ll need to have a database created before we can install Wordpress. In your web browser, navigate to http://localhost/phpmyadmin and login. There should be the default user and password if this is your first time. Find it by clicking the VertrigoServ icon in the bottom right tray, and selecting “Help and Readme”. Be sure to change your passwords once you get in. Default login is root/vertrigo.
Now that we’re in PHPmyAdmin, let’s create a database for our local Wordpress install. Type in your desired database name, and hit the “Create” button.

With the database created, we can now input our database details into the wp-config.php file of our WP install.
1 2 3 4 5 6 7 | // ** MySQL settings ** // define('DB_NAME', 'database_name'); // The name of the database from step 2 define('DB_USER', 'root'); // Vertrigo uses root as the default username define('DB_PASSWORD', 'vertrigo_password'); // the password used to get into your local phpmyadmin define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value define('DB_CHARSET', 'utf8'); define('DB_COLLATE', ''); |
Now we can pull open our browser, and navigate to http://localhost/wordpress and begin the installation of Wordpress.
The http://localhost/ address looks into the \usr\www\ directory. So whatever the name of the directory we installed in, is what we’ll need to punch in after localhost/. For example, if I installed an application in \usr\cms\, I will need to navigate to http://localhost/cms in order to pull up that site.