How to Protect SEO Performance During a Site Migration
Arming yourself with the right tools to ensure a smooth site migration is important - find out how to protect your SEO during a migration today.
Read moreHave your thumbnails gone missing since upgrading to WordPress 3.4? Are you using the Auto Post Thumbnail plugin? Turns out you’re not alone.
The problem is down to the new way WordPress stores additional data (metadata) associated with a post - in this case the thumbnail WordPress should display on index pages etc.
A hotfix has appeared but it only fixes the issue when you add a post – it does not fix existing images. Another hotfix involves deleting all broken images and running the plugin's Generate Thumbnails tool, but this has a fundamental flaw in SEO terms: your existing image URLs will no longer be discoverable and your pictures will soon enough drop out of Google Images. Bye bye traffic...
Retaining your existing image URLs is simply a matter of re-establishing the link in the database between your post and its long-lost thumbnail. To do this, copy the following code into a PHP file (e.g. imagefix.php ) and upload this to your webroot. Then fire up a browser and visit the page you just uploaded e.g. http://www.example.com/imagefix.php.
The script should take less than a minute to do its thing and voilà: your templates and galleries will look just the way you remember - and Google will never know what all the fuss was about!
Note: as well as running the script you should install the hotfix here upgrade the plugin, so that future posts continue to auto-add the thumbnail.
DISCLAIMER: Use this code at your own risk. It is largely untested and ClickThrough Marketing take no responsibility for any issues that may arise due to its use. TAKE A BACKUP OF YOUR DATABASE BEFORE RUNNING THIS SCRIPT.
<?php
ob_implicit_flush(1);
require_once("wp-load.php");
echo 'Working... '; ob_flush();
$sql = 'SELECT meta_value FROM `'.$wpdb->postmeta.'` WHERE meta_key="_thumbnail_id" ORDER BY post_id DESC';
$posts = $wpdb->get_results($sql);
foreach ( $posts as $post ){
$sql = 'SELECT meta_id FROM `'.$wpdb->postmeta.'` WHERE post_id = '.$post->meta_value.' AND meta_key = "_wp_attached_file"';
$check = $wpdb->get_results($sql);
if(count($check)) continue; // We've already done this one...
$sql = 'SELECT meta_key,meta_value FROM `'.$wpdb->postmeta.'` WHERE post_id = '.$post->meta_value.' AND meta_key = "_wp_attachment_metadata"';
$thumb = $wpdb->get_results($sql);
$data = unserialize($thumb[0]->meta_value);
if(!isset($data['sizes']['thumbnail']['file'])) continue;
$date = dirname($data['file']);
$filename = $data['sizes']['thumbnail']['file'];
$sql = 'INSERT INTO `'.$wpdb->postmeta.'` SET post_id='.$post->meta_value.', meta_key="_wp_attached_file", meta_value="'.$date.'/'.$filename.'"';
$wpdb->query($sql);
}
echo 'done!';
?>
More articles you might be interested in:
Arming yourself with the right tools to ensure a smooth site migration is important - find out how to protect your SEO during a migration today.
Read moreGoogle employees have recently announced that the upcoming Google Core Update is set to be released in the coming weeks. Understanding and addressing...
Read moreLanguage matters. Any marketer worth their salt knows this. But when discussing gender and sexual orientation, that importance is amplified tenfold.
Read moreAdvertising via Google is constantly evolving, and new ways to showcase your brand and business offering are regularly being rolled out. The latest...
Read moreWhen marketers think of thought leadership, there are names rather than ideas, that tend to spring to mind.
Read moreThe UK market has been waiting with bated breath for Google’s Vehicle Ads release – so where is the update? Learn more.
Read moreAs Google turns 25, we’re taking a look back at our favourite Google moments. Which features have made the biggest impact on digital marketing on...
Read moreWith the release of GPT-4, how revolutionary will this tool be? Alan Rowe takes us through it...
Read more