Is this meta tags in header.php correct as google plus is u

Is this meta tags in header.php correct as google plus doesnt pick my correct excerpt description & title for any pages ex http://share-ask.com/what-will-you-choose-in-love-vs-money-debate

<title><?php wp_title(''); ?><?php if (!(is_404()) && (is_single()) || (is_page()) || (is_archive())) { ?><?php } ?><?php bloginfo('name'); ?></title>

<link href=”https://plus.google.com/u/0/b/113318855145805261610/+Shareaskarticles” rel=”publisher” />  
<!--Facebook Open Graph-->

<meta property="og:title" content="<?php the_title();?>" />
<meta property="og:description" content="<?php the_excerpt();?>" />
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?php the_permalink();?>" />

<meta property="og:site_name" content="<?php bloginfo('name');?>" />

<?php

 if(has_post_thumbnail()){

$post_thumbnail=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'large');

               $post_thumbnail_image=$post_thumbnail[0];

               ?>

               <meta property="og:image" content="<?php echo $post_thumbnail_image;  ?>" />

               <?php

              }

?>
<meta property="fb:app_id" content="1745549792386507">
<meta property="fb:admins" content="100008701029873">



<!--Twitter Cards-->
<?php

#twitter cards hack

if(is_single() || is_page()) {

 $twitter_url    = get_permalink();

 $twitter_title  = get_the_title();

 $twitter_desc   = get_the_excerpt();

   $twitter_thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );

    $twitter_thumb  = $twitter_thumbs[0];

      if(!$twitter_thumb) {

      $twitter_thumb = 'http://share-ask.com/wp-content/uploads/popular-debate-topics-for-high-school-students.jpg';

    }

  $twitter_name   = str_replace('@', '', get_the_author_meta('twitter'));

?>

<meta name="twitter:card" value="summary_large_image" />

<meta name="twitter:url" value="<?php echo $twitter_url; ?>" />

<meta name="twitter:title" value="<?php echo $twitter_title; ?>" />

<meta name="twitter:description" value="<?php echo $twitter_desc; ?>" />

<meta name="twitter:image" value="<?php echo $twitter_thumb; ?>" />

<meta name="twitter:site" value="@shareask" />

<?

  if($twitter_name) {

?>

<meta name="twitter:creator" value="@<?php echo $twitter_name; ?>" />

<?

  }

}

?>
1 Like

Looking at the page source the problem seems to be the description is missing.
I notice in the posted code that you are using two different functions to get the description for open graph : the_excerpt();, and twitter :get_the_excerpt();.
But neither seem to be working.
Do you have the code for those functions?

FYI That is the full code I’VE in header.php & im also trying to add code which will add meta title,description, automatically for each page

the yoast plugin tends to do this sort of thing quite well, it can add stuff like Open Graph for Facebook, Twitters cards and the relevant meta data for Google Plus, not sure if you are using something similar but using yoast would save you messing about with the code…

I agree but due to shared hosting i prefer not to use plugins

the_title(); and the_excerpt(); must be used within a WordPress loop.

1 Like

Yes, I had just looked up those WP functions, the reference for get_the_excerpt() says:-

This function must be used within The Loop when no $post parameter passed.
https://codex.wordpress.org/Function_Reference/get_the_excerpt

Not that I know what “The Loop” is, not being a WP user. :shifty:

The Loop is a php loop that pulls in the posts from the database. In its simplest form it is like this:

<?php if (have_posts()) : while (have_posts()) : the_post() : ?>
// then all sorts of choices of functions such as the_title(), the_excerpt(), the_content()
<?php endwhile; endif; ?>

Of course you have access to a lot of parameters to use here or with the WP_Query object to customize which posts you want.

In the head, you could use <?php blog_info('description'); ?> or <?php blog_info('name'); ?>` etc.

Just look up these in the WordPress documentation to see all the options you can have.

Looking at the OP’s code, I don’t see any such while loop, so that could be the issue.
In the source of their page all the other OG and Twitter fields seem to be working OK, just the description is missing.

The loop never goes in the head. So the OP could use blog_info('description') for that. The description here is entered in the settings part of the dashboard, under ‘general’ where the site owner can enter a tagline.

But i need to add meta title,description, automatically for each page not just home which code is not doing it just pics home page title,description

which code u want can u specify
the_excerpt();, and twitter :get_the_excerpt();. are normal wordpress function

so how to fix it as i cant share in G+

Things haven’t changed all that much since you last asked about adding <head> tags a few weeks ago.

The answer is the same, use a plugin or hard-code them in.

2 Likes

Dat y im saying if can correct my code posted above it will solve my g+ issue

Why not give this one a try

Inserts Facebook Open Graph, Google+/Schema.org, Twitter and SEO Meta Tags into your WordPress Website for more efficient sharing results.

I already said plugins i dont use bcoz i cant upgrade to advance hosting bcoz of the cost,so im trying to fix dis via code

Here im using same theme http://bpshbp.ipage.com/work-hard-play-hard/ which shares in G+ accurately ,then y i cant share here http://share-ask.com

I overwrited code also but no use

Ah, that does bring up an option I hadn’t thought of.

There most likely are themes available that have the open graph tags etc. as part of the theme. Basically a theme with a plugin built-in as part of the theme.

I don’t know of any such themes off-hand, but if you search you should be able to find something.

Im using same theme http://bpshbp.ipage.com/work-hard-play-hard/ which shares in G+ accurately ,then y i cant share here http://share-ask.com WHEN using same theme

so dere is no point in searching a theme which is already workin gr8 http://bpshbp.ipage.com/work-hard-play-hard/ ,

Yes, they are WP functions. But as mentioned earlier, they will only work within a Loop.

This function must be used within The Loop when no $post parameter passed.

Or it seems get_the_excerpt() can be used with a $post parameter if not in a loop.