Wrong image URLs after migrating to Bedrock

I’m migrating an existing WordPress site (a custom theme that I developed) to Bedrock. I manually migrated over the theme files, put the plugins in composer.json, put the media files in the right place, did a wp search-replace for the old and new url, and then did a search-replace for /wp-content to /app.

However, I’m having an unexpected result. get_the_post_thumbnail() and wp_get_attachment_image_src() are both returning the image urls in the following format:

/wp/app/uploads/09/12/filename.jpg

Have I done something wrong in the migration? Any suggestions?

For what it’s worth, I did already try a search-replace for /wp/app to /app and there were no instances found

Have you checked what media URL’s look like in the database now?

I did a search in mysql and this is an example of what I’m seeing in the wp_postmeta table:

meta_key = '_wp_attached_file'
meta_value = '2016/09/filename.jpg'

I’ve ran into this a few times but I forget exactly what it is. I believe it was a setting in the database that was causing these problems for me, possibly related to media folder location.

Do you happen to be using an older Roots theme as well?

I am using Sage, but it couldn’t have been any earlier than January or February of this year.

Thank you, that was just enough to figure it out. Using Phpstorm and Xdebug, I traced wp_get_attachment_image_src() all the way back until _wp_upload_dir() and found the problem. It would appear that if a value for upload_path is set in the database, it joins that upload path with ABSPATH to make the upload_dir_path. However, if it’s empty, it simply joins the WP_CONTENT_DIR constant with ‘/uploads’ which is obviously what we wanted.

Short story, I deleted the upload_path from wp_options table and now everything works as expected.

Really appreciate the help in pointing me the right direction.

3 Likes