• ive read about main seo plugins and find most of them overbloated, and forums are full of people with lot of issues caused by those plugins

    my main intention is to add meta description to each post custom one written by me, is there any way to do this using custom fields without suing any plugin in wordpress 2.9.2

    and what about wordpress 3.

    thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter userword

    (@userword)

    any idea

    Thread Starter userword

    (@userword)

    if someone knows for sure that it is not possible at all i would appreciate her or him to tell it to me

    thank you very much

    this snippet in header.php in the <head> section might do it:

    <?php if( is_single() ) {
    $meta_desc = get_post_meta($post->ID, 'metadescription', true);
    if ($meta_desc) { echo '<meta name="description" content="'.$meta_desc.'" />'; }
    }
    ?>

    put the name of your customfield instead of ‘metadescription’

    untested

    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!!

    The code would go into your theme’s header.php … (between the <head> tags)

    Can’t speak in regard to the code though, i don’t use anything like that myself to know which works..

    Thank you so much, Mark.
    It’s a start.
    I hope someone knows about codes!

    userword said, “read about main seo plugins and find most of them overbloated, and forums are full of people with lot of issues caused by those plugins”.
    I read as well and feel concerned to add one of those SEO plugins.
    I just wanted to find the simplest, easiest, cleanest way to add meta description…

    <?php if( is_single() ) {
    <meta name="description" content="<?php the_excerpt(); ?>" />
    ?>

    Above code will add meta description to posts only, This will show first 55 words If you are not writing excerpt manually, else it will show the content of excerpt field.

    But if i would like to add a meta description for categories page only and left that my plugin Headspace2 add the meta description to posts and page what i have to do?
    adding the followin code in <HEAD> section of header.php
    <meta name="description" content="<?php if ( is_category() ) { echo category_description(); } ?>"/>

    the meta description of posts and pages disappear and off course category pages description is added.

    This code

    <?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; ?>

    added in the header works a charm. The trick is to make sure that the_post() references are only used in if statements where the value exists only for the life of the statement (When used it the header). Pages start to vanish otherwise… not forever, the_content() etc references just stop returning anything. I played with removing the the_post() ref from the body of my pages (to avoid the issue above) but all that did was result in a description always equating to the latest post as opposed to the page you are trying to make unique.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘anyway to add meta description to post without plugin’ is closed to new replies.