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

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.


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+/, 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 which shares in G+ accurately ,then y i cant share here

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 which shares in G+ accurately ,then y i cant share here WHEN using same theme

so dere is no point in searching a theme which is already workin gr8 ,

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.

so what should be my correct code plz guide

Try this - Place this code above the doctype in your header.php file:

	$postid = get_the_ID(); 
	$excerpt = get_the_excerpt( $postid );

Then your description code would be:

<meta name="description" content="<?php echo (NULL != $excerpt) ? $excerpt : '' ; ?>" />

in your <head>

1 Like

I’ve placed code still <meta name=“description” is empty

One approach to dynamically add page description / meta is to use a plugin named “Advanced Custom Fields” where you create a custom field with this slug for exemple “page_description” and then on each page/post you manually populate this field (there is a meta box on edit page also). At the end you could use ACF dedicated function “get field” (see the documentation) to display in the necessary informations.
As your question indicate that you prefer not to use plugins due to your hosting type, the same result can be achieved with WP custom fields, in this case you need to get the page/post ID first then display the slug of the custom field (if have posts, get the id > display the slug for this id).
Using this give you total liberty on post/page description (since it is limited in length) to provide a complete sentence, with your keywords and good description,not a 200 chars excerpt stripped that could say nothing. Prefer to use one meta description in the code.
Cheers !

The OP has already stated that they do not want to use a plugin for this.
Please read the topic before posting.

Excerpts only work for posts, not pages. And if you have not written an excerpt for the post on its edit page, there will not be an excerpt to display unless the theme you have auto-generates the excerpts.

no i dont want manual options ,do u have auto-excerpt option only as i’ve 2000 post on my site

Try putting a loop in your <head>. This seemed to work for my local test site. But automatically generated excerpts have […] at the end, which you might not want in a description. I will see if I can remove that.

<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php remove_filter('the_excerpt', 'wpautop'); ?>
	<meta name="description" content="<?php the_excerpt(); ?>" />
<?php endwhile; endif; endif; ?>