The WP SEO Structured Data Schema plugin lets you implement structured data and schema on your website. One of the things you can set is the publisher image. This can be done in the global settings of the plugin and for each post individually. What if you decide to change the image?
Unfortunately, changing the image in the global settings won’t have any effect on existing posts. The new image will be applied only to new posts. One solution is to go through all your posts and update the image. This is fine for a few posts, but what if you have thousands of them?
To update all your posts, you can run the following SQL query in your database:
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '\"publisherImage\"\;s:5:\"12345\"', '\"publisherImage\"\;s:5:\"54321\"') WHERE meta_key LIKE '%schema%';
Before you run the query, you need to modify it so that it reflects your situation.
- Check your table prefix if it’s
wp_like in my case. This can be checked in Tools → Site Health → Info (tab) → Database → Table prefix.
- Check the ID of the current publisher image. Go to Media → Library, select the old image and check the URL. You should see something like
12345is your old image ID.
- Change the length of the image ID, if necessary. The length is set in the
s:5(it’s 5 in my example).
- Check the ID of the new image and its length, and set the
s:accordingly. In my example, it’s
s:parameter doesn’t match the length of the image ID, the change won’t be successful.
After you made all the necessary changes to the query, run it and it should update all your posts with the new publisher image.
TIP: you can run the query for 1 post to check if the query is correct:
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '\"publisherImage\"\;s:5:\"12345\"', '\"publisherImage\"\;s:5:\"54321\"') WHERE meta_key LIKE '%schema%' AND post_id = 78;
How to check the ID of an image that’s been already removed from the database
If you have already removed the old image from your library, you’ll need to check the ID in your database with an SQL query:
SELECT meta_value from wp_postmeta WHERE meta_key LIKE '%schema%' AND meta_value LIKE '%publisherImage%' ORDER BY post_id DESC;
If you click on one of the results, you’ll see the image ID and its length next to the „publisherImage” string.