Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Personal blog with occasional guest authors (non-commercial) self hosted Wordpress. I create a bespoke author PHP file for each author (example).
I use Yoast SEO and set a default image for meta property='og:image' where one isn't specified for a post or page for sharing to Facebook / Google+, etc.

Is there any way I can over-ride the default image for the archive page for each author.
This could be done by coding either the individual author archive page or adding something to functions.php. Appreciate any guidance at all.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Try copying the following code into your functions.php file.

It adds a custom og:image property for the authors with nicenames of michelle-robinson, mystery-man, john-smith, and a default fallback image, respectively. You can easily change this to suit your needs.

add_action( 'wp_head', 'wpse_70701_author_image' );

function wpse_70701_author_image() {
    if ( is_author( 'michelle-robinson' ) ) {
        // set a custom image if we're visiting Michelle Robinson's author page
       echo '<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-michelle-robinson-image.png" />';
    }
    elseif ( is_author( 'mystery-man' ) ) {
        // set a custom image if we're visiting Mystery Man's author page
       echo '<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-mystery-man-image.png" />';
    }
    elseif ( is_author( 'john-smith' ) ) {
        // set a custom image if we're visiting John Smith's author page
       echo '<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-mystery-man-image.png" />';
    }
    else {
        // set the default fallback image (you may want to omit this section)
       echo '<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-author-image.png" />';
    }
}

Here, I've given the function a unique name, but you can call the function anything you want, as long as it is not already the name of another function. If you rename the function, you also need to edit the add_action hook.

share|improve this answer
    
Thank you bungeshea I'll give it a try. I'm quite new to Wordpress and PHP is the function wpse_70701_author_image() just a random name you've given the function? i.e. I could call it anything as long as there's no conflict? Also if there were say 3 authors would I need to write a new differently named function each time or would I just add another if section to this function (I get confused with if, ifesle, else). Many thanks. –  Skip Oct 28 '12 at 12:00
    
You can call the function virtually anything you want, as long as it is not the name of another function. You also change the function name in the add_action hook. I chose to start the function off with wpse_70701_, because this is question number 70701 on WordPress Stack Exchange. Also, I've updated the answer to deal with more authors. –  bungeshea Oct 28 '12 at 19:06
    
Hi bungeshea I loaded the original code with an amended function name and it works perfectly adding the meta info tothe header. Thank you - question definitely answered :-) –  Skip Oct 28 '12 at 23:40
    
@Skip I'm glad I could help :-) –  bungeshea Oct 29 '12 at 2:27
add comment

If I understand correctly, you want to change the default image for each author on a WP install? Try this plugin http://wordpress.org/extend/plugins/user-photo/

Alternatively, you can make a separate template for each author (if applicable).

share|improve this answer
    
Thank you siouxfan45. Not quite I don't think. I'm not looking for the image to display on the page necessarily. I just want to amend the meta property='og:image' in the head for each author template - I already create a specific template for each author but it takes the header meta data from elsewhere (header.php I assume) - the template just covers the body elements. I want the meta property='og:image' to be the author's image. Hope that makes sense. If you look at the example link you'll probably see the header data and I need to find a way to edit that for specific author archives. –  Skip Oct 27 '12 at 23:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.