If you just migrated your website from localhost or different url, like staging one, to the live website, there is a chance you will see broken images in some pages and posts. One of the ways To fix broken images after WordPress migration is through cPanel.

Broken images issue happens if you have uploaded images inside the content editor, and image is not referenced by id, but by your old website url.

So if you changed domain path, like from yourwebsite.com/staging to the yourwebsite.com, all images that were uploaded into the to the post content will keep the saved url leading to your old website.

To fix this, log in to your cPanel, and select phpMyAdmin option:

Thenin the left side menu, you will see the databases list. You need to select your WordPress website databse, and then select the SQL tab from the top bar:

And paste the following code as show on the screenshot above:

UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://yourwebsite.com/blog', 'http://yourwebsite.com');
UPDATE wp_posts SET post_excerpt = REPLACE (post_excerpt, 'http://yourwebsite.com/blog', 'http://yourwebsite.com');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://yourwebsite.com/blog','http://yourwebsite.com');
UPDATE wp_termmeta SET meta_value = REPLACE (meta_value, 'http://yourwebsite.com/blog','http://yourwebsite.com');
UPDATE wp_comments SET comment_content = REPLACE (comment_content, 'http://yourwebsite.com/blog', 'http://yourwebsite.com');
UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'http://yourwebsite.com/blog','http://yourwebsite.com');
UPDATE wp_posts SET guid = REPLACE (guid, 'http://yourwebsite.com/blog', 'http://yourwebsite.com') WHERE post_type = 'attachment';

Just replace http://yourwebsite.com/blog with your old website url, and http://yourwebsite.com with your new website URL. THen click the Go button in the bottom right corner. This will run the query and update your website url everywhere.

If you used custom database prefix when installing your WordPress website, from wp_ to something different, then in the code above replace wp_ with your WordPress database prefix.

After query has run, re-visit your website. All broken images should be fixed