WordPress Photo Selection / Rotation Using Option Field

A white, rounded square logo with an abstract S-shaped design on a gradient blue and purple background.

Can WordPress have a nice photo selection tool for the main header area for any post or pages of the web site? Can it default to a standard photo, if I don’t want to choose one?

Hell, yes!

How To
Just plugin this code where the usual photo in the header is placed.

<img src=”/wp-content/themes/paperstreet/images/photos/<?php $key=”photo”; if(get_post_meta($post->ID, $key, true) != “”) echo get_post_meta($post->ID, $key, true); if(get_post_meta($post->ID, $key, true) == “”) echo “girl.jpg”; ?>” />

Next, using the handy administrative area of WordPress create a OPTION field in the actual WordPress Page/Post that you are using. Call the option field KEY “photo”. Then put the image name in the value field (i.e. girl.jpg) that you want to use. Of course, that photo needs to be uploaded to the correct directory, in this case /images/photos/ of the current paperstreet theme.

The above will pull from the photo option field that you added to the page/post. It will default to “girl.jpg” if you do not put in an option field. Of course change “girl.jpg” above if you want to use a different image.

Share This

Join the Sales and Marketing News, receive our last insights, tips and best practices.

Our 7 Guarantees

Keeping 2,000+ Clients Happy Since 2001.

You Will Love Your Design We design to please you and your clients
Same-Day Support 24-hour turnaround edits during business hours
Free Education We provide knowledge to help you expand
No Hidden Charges We quote flat-rate projects
Own Your Site No strings attached
We Create Results SEO, PPC, content + design = clients
We Make Life Easier One agency for web, branding and marketing