Hi there,
userword, have you found the way?
if so, will you share it with us?
alchymyth, have you heard from anyone that your snippet works?
I have been looking for a way to add meta description without plugin as well.
I searched google and found so many different ways… without any indication that they work.
Here are some examples —
<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php the_excerpt_rss(); ?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>
or
<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php the_content_limit(200)?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>
or
<meta name="description" content="<?php
// if home page output blog name and description
if (is_home()) { bloginfo('name'); echo " - "; bloginfo('description');}
// if single page output either excerpt if available or post title
elseif (is_single()) {
$custommeta = get_post_meta($post->ID, "MetaDescription", true);
// checks ot see if the custom field MetaDescription is not empty
if ($custommeta !=='') {echo $custommeta;}
// check if excerpt exists for the post and output it if it does
elseif (!empty($post->post_excerpt)) {the_excerpt();}
// if there's no custom field or excerpt output the post title
else {single_post_title('', true);}
}
// if category page output the category description
elseif (is_category()) {echo category_description();}
// if it's any other page display this generic description
else { echo 'Add your own generic site description here';}
?>"
/>
Sadly, I have no idea what is what here…
Will anyone please tell me which one actually works?
And also where am I supposed to add these codes?
Thank you so much!!