0

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.

2 Answers 2

1

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.

4
  • 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
    Commented Oct 28, 2012 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.
    – shea
    Commented Oct 28, 2012 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
    Commented Oct 28, 2012 at 23:40
  • @Skip I'm glad I could help :-)
    – shea
    Commented Oct 29, 2012 at 2:27
0

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).

1
  • 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
    Commented Oct 27, 2012 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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