Support » Plugins » Google authorship using custom profile meta field

  • Tom



    I’m using the following code to remove some of the default profile fields and add more useful ones:

    	Remove user profile fields and add in our own
    function add_twitter_contactmethod( $contactmethods ) {
    	// Add Twitter
      if ( !isset( $contactmethods['twitter'] ) )
        $contactmethods['twitter'] = 'Twitter';
    	// Add Facebook
      if ( !isset( $contactmethods['facebook'] ) )
        $contactmethods['facebook'] = 'Facebook';
    	// Add Google+
      if ( !isset( $contactmethods['googleplus'] ) )
        $contactmethods['googleplus'] = 'Google+';
      // Remove Yahoo IM
      if ( isset( $contactmethods['yim'] ) )
        unset( $contactmethods['yim'] );
      // Remove AIM
      if ( isset( $contactmethods['aim'] ) )
        unset( $contactmethods['aim'] );
      // Remove Jabber/ Google Talk
      if ( isset( $contactmethods['jabber'] ) )
        unset( $contactmethods['jabber'] );
      return $contactmethods;
    add_filter( 'user_contactmethods', 'add_twitter_contactmethod', __('add_facebook_contactmethod', __('add_googleplus_contactmethod', 10, 1 )));

    I can then retrieve the data for those fields on the front end, for example to retrieve the Googleplus field data I would use:

    <?php the_author_meta( 'googleplus', $author_id ); ?>

    Now, what I’d like to do is add a link to head section of the site, for Google authorship.

    One way to do this would be to add the following to the themes functions.php file:

    add_action('wp_head', 'add_our_google_rel_author');
    function add__our_google_rel_author() {
    echo '<link rel="author" href="" />';

    This would insert the link to the head of each page on the site, however this would insert the same author link on each page.

    What I’m looking to do instead is, take the data from the custom Google+ profile field and insert that in the head, dynamically. This way, the author link will be added dependent on who is the author of a page.

    I’m assuming I’d need to run this within the loop inside the head?

    I’m not very good with PHP so would appreciate any help with this,


Viewing 1 replies (of 1 total)
  • Hey Tom —

    To grab the author meta info outside of the loop you’ll need to reference the global $post variable.

    Try this:

    add_action('wp_head', 'dvc_google_rel_author');
    function dvc_google_rel_author() {'
    	global $post;
    	echo '<link rel="author" href="'. get_the_author_meta( 'googleplus', $author_id ) .'" />';
Viewing 1 replies (of 1 total)
  • The topic ‘Google authorship using custom profile meta field’ is closed to new replies.