0

How to set filename as image title in the media gallery of Wordpress, using wp-cli ?

In other words, I'd like my image titles, stored in wp-content/uploads to be exactly their image filenames (without the extension ".jpg").

In the end, I'd like the two commands below to ouput the same value, for every image in wp-content/uploads:

$ wp post get 17136 --field='guid'
https://www.example.com/wp-content/uploads/albar-vert-oihan-692X692-03-14.jpg

$ wp post get 17136 --field=title
albar-vert-oihan-692X692-03-14

I'd like to do the following for every image:

wp post update 17136 --post_title=$(echo "$(basename $(wp post get 17136 --field=guid))" | cut -f 1 -d '.')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.