WordPress® Photo Selection / Rotation Using Option Field
Question
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?
Answer
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.
About Us
Did you know more than 200 clients have worked with PaperStreet for more than 10 years?