How to set up featured images on your WordPress.org blog

If your WordPress.org blog (that’s the self hosted one) is below version 3.4 and 3.1 or above you can add some code to enable featured images. You will need ftp access or access to the website’s file system to make these changes.

NOTE: If you are running WordPress 3.4 or higher (or your blog is hosted by WordPress.com) you will be able to set featured images using BlogPad Pro without making these changes.

Step 1:

Find the wp-includes directory in your WordPress.org blog. You will need to edit two files from this directory. It’s a good idea to make back-up copies of these files before you make any changes to them.

Step 2:

Open the file: class-wp-xmlrpc-server.php

find this code:

$attachment_struct = array(
	'date_created_gmt'	=> new IXR_Date($attachment_date_gmt),
	'parent'		=> $attachment->post_parent,
	'link'			=> $link,
	'thumbnail'		=> $thumbnail_link,
	'title'			=> $attachment->post_title,
	'caption'		=> $attachment->post_excerpt,
	'description'		=> $attachment->post_content,
	'metadata'		=> wp_get_attachment_metadata($attachment->ID),
);

and replace with this:

$attachment_struct = array(
	'attachment_id'		=> $attachment->ID,
	'date_created_gmt'	=> new IXR_Date($attachment_date_gmt),
	'parent'		=> $attachment->post_parent,
	'link'			=> $link,
	'thumbnail'		=> $thumbnail_link,
	'title'			=> $attachment->post_title,
	'caption'		=> $attachment->post_excerpt,
	'description'		=> $attachment->post_content,
	'metadata'		=> wp_get_attachment_metadata($attachment->ID),
);

Step 3:

In the same file change this code:

return apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ), 'upload' );

to this:

return apply_filters( 'wp_handle_upload', array( 'attachment_id' => strval($id), 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ), 'upload' );

Step 4:

Open the meta.php file and replace this code

function is_protected_meta( $meta_key, $meta_type = null ) {
	$protected = ( '_' == $meta_key[0] );
	return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
}

with this:

function is_protected_meta( $meta_key, $meta_type = null ) {
	if ($meta_key == '_thumbnail_id') {
		$protected = false;
	} else {
		$protected = (  '_' == $meta_key[0] );
	}
	return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
}

Once the fields have been saved, featured images should work on your blog!

Please note:

  • If your version of WordPress.org is older than version 3.1 you won’t be able to set featured images.
  • If you make this change after you have added your blog to BlogPad Pro, you will need to refresh your BlogPad Pro media library before this feature will work.
Advertisements