Bulk update of the publisher image in WP SEO Structured Data Schema

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.

  1. 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.
  2. 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 https://your-website.com/wp-admin/upload.php?item=12345. The 12345 is your old image ID.
  3. Change the length of the image ID, if necessary. The length is set in the s:5 (it's 5 in my example).
  4. Check the ID of the new image and its length, and set the s: accordingly. In my example, it's 54321 and 5.
If the 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.

Pani Marta
Jestem Marta. Pani Marta. I piszę o rzeczach, które inspirują mnie i ciekawią w pracy web developera. Na moim blogu znajdziesz porady dotyczące WordPressa i programowania stron, a także moje osobiste przemyślenia na najróżniejsze tematy.

Masz pytania lub uwagi? Zostaw komentarz :-)

Pola oznaczone gwiazdką są obowiązkowe.

Podaj swoje imię lub nazwę. Ta nazwa będzie widoczna przy Twoim komentarzu.
Napisz komentarz.