php in header out of the loop
-
I put an extra user field in the user profile called
Field Name: Google Site Verification number
and a
Meta Key: google_verification .I’m trying to insert it like this
<meta name="google-site-verification" content="<?php the_author_meta('google_verification');?>" />
into the headerIf i insert this in the template it outputs
<meta name="google-site-verification" content="theInfoFromTheField" />
If i insert this in the header it outputs
<meta name="google-site-verification" content="" />
Any Help?
Thank You!
-
i just tried the function but it returns empty in the body and in the header
if i put the UserID in the function call, it works in both cases
the_author_meta('facebook',1);
Ah! yes. That works in the header. thank you
Now what i want to do is take what this renders.
<?php the_author_meta('google_verification'1);?>
(which is a string like this, oheG_Lp3GVqp-_WY_cK03iW9rJWfpDF2ZEOSxpJAT5c)And Insert it here
<head> <meta name="google-site-verification" content="Insert it here" /> </head>
On the fly depending in page Author.
for what i understand, the author’s ID is only available inside the loop
i’m not sure, but would be worth try/search if you can run a single query loop inside the header
but that (if works) would have to contemplate the pages that list many posts (archive, category, search, index)
Since the Google verification meta tag is specific to the site rather than the author, it may make more sense to store it using update_option() rather than
update_usermeta()
. Then you could access the information anywhere using get_option().Yes but what I’m trying to do is allow users to verify
b_http://mysite.com/theirPages as their own. To allow them to verify then set up adsense.Let me try to clarify what I’m trying to do.
I’m setting up an adsense share.
In my users (lets call them authors) profiles I have a field where they enter their adsense publisher id. (pub-xxxxxxxxxxxxxxxx) I then use this field and insert it into two ads using<script type="text/javascript"><!-- google_ad_client = "<?php the_author_meta('google_id');?>"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; google_color_border = "F4F1E9"; google_color_bg = "F4F1E9"; google_color_link = "CC0000"; google_color_text = "000000"; google_color_url = "CC0000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
This gives them 100% ownership of these two ads.
This is great if they already have an Adsense account. However, I would like them to be able to apply for an Adsense account thru my domain. (As opposed to say Blogger.com)But google wants you to have a website.
Now to verify a site Google webmaster central gives you two options.
1.) upload a file
2.) Add a meta tag to the top of your page. like this,
<meta name="google-site-verification" content="455_h5u_f2h_6sw_b21_66i_v8e_5ml_554_1k2" />
I have a second field in the author profile called google-site-verification
where they can enter the 455_h5u_f2h_6sw_b21_66i_v8e_5ml_554_1k2So what I want to do is post the user field google-site-verification
into here in the header
<meta name="google-site-verification" content="POSTHERE" />
so that google will consider their profile and every page authored by them as their website.To get the author ID of a single page in the header, you can use this:
$wp_query->post->post_author
I believe this returns the author ID of the last queried post on non-singular pages (such as the blog page, catgory pages, etc.), so don’t depend on it in those situations. This might do what you want:
<?php if ( is_singular() || is_author() ) { $google_verification = the_author_meta( 'google_verification', $wp_query->post->post_author ); if ( isset( $google_verification ) ) { echo '<meta name="google-site-verification" content="' . $google_verification . '" />'; } } ?>
You might have to do
global $wp_query;
beforehand, but I doubt it.Thank You Big Bagelyou to brasofilo.
Worked like a charm! I’m just an old copy n paste hack and really wish I understood more of PHP. Hats off to you!
Thanks again!
- The topic ‘php in header out of the loop’ is closed to new replies.