• kmcminn

    (@kmcminn)


    Hello, everyone. This shouldn’t be difficult, but I can’t figure it out. By default, WordPress doesn’t add any meta description tags. They have to be added manually, or by using a plugin.

    I’ve tried adding this to my header:
    <meta name="description" content="My meta description for my website" />

    …but that’s not correct because it’ll add that to ALL pages and posts.

    Does someone know of a query I can use inside the header that allows me to use my main site description for only the homepage and uses the title of the post, for posts?

    I don’t want a plugin for this.

Viewing 15 replies - 1 through 15 (of 23 total)
  • kmessinger

    (@kmessinger)

    Thread Starter kmcminn

    (@kmcminn)

    I had a feeling someone was going to reference that. I should have already pointed out that I tried that. Do you realize the code is wrong?

    <meta name="description" content="<?php if ( is_single() ) {
            single_post_title('', true);
        } else {
            bloginfo('name'); echo " - "; bloginfo('description');
        }
        ?>" />
    Michael

    (@alchymyth)

    you will rarely find ‘copy/paste’ solutions in the Codex;

    a different example:

    <meta name="description" content="<?php if( is_home() ) { ?>
      your meta description for the home page
    <?php } elseif ( is_single() ) {
      single_post_title();
    } else {
      bloginfo('name'); echo " - "; bloginfo('description');
    } ?>" />

    to find out if you need to use ‘is_home()’ or ‘is_front_page()’ see https://codex.www.ads-software.com/Conditional_Tags#The_Main_Page

    catacaustic

    (@catacaustic)

    What’s wrong with that code? I have looked at it quickly and I can’t see any problems.

    In response to your main question, you are correct. WordPress does not add the meta description tag in by default. Mainly because it’s being devalued by pretty much every major search engine out there so it’s almost no use at all, if any. If you want it you can use one of the many plugins that are out there as these will give you what you’re after and allow you to set the tags content with what you want. I’d suggest that you look at some of teh overall SEO plugins that are available as they do this and a lot more to help you sort out the SEO for your site.

    kmessinger

    (@kmessinger)

    Do you realize the code is wrong?

    I would have no way to tell.
    Can you correct and use it?
    https://codex.www.ads-software.com/Conditional_Tags

    but that’s not correct because it’ll add that to ALL pages and posts

    So? That is not going to cause a problem.

    Thread Starter kmcminn

    (@kmcminn)

    @alchymyth

    I’ve double-checked my “Front page displays” setting in Settings > Reading and it’s set to “Your latest posts.”

    So, checking that with the URL you referenced, I should be using “is_front_page()” for my example.

    Would this look correct then?

    <meta name="description" content="<?php if( is_front_page() ) { ?>
      your meta description for the home page
    <?php } elseif ( is_single() ) {
      single_post_title();
    } else {
      bloginfo('name'); echo " - "; bloginfo('description');
    } ?>" />
    Thread Starter kmcminn

    (@kmcminn)

    @catacaustic

    I think it’s the way I was using the code. As alchymyth pointed out, there are rarely cases where exact copy and paste jobs will work; as everyone’s site is different. I think that’s where I went wrong.

    Michael

    (@alchymyth)

    I’ve double-checked my “Front page displays” setting in Settings > Reading and it’s set to “Your latest posts.”

    should be ‘is_home()’ in that case.

    Thread Starter kmcminn

    (@kmcminn)

    Doesn’t that contradict this then?

    The Front Page

    is_front_page()
    When the front of the site is displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed and the ‘Settings > Reading ->Front page displays’ is set to “Your latest posts”, or when ‘Settings > Reading ->Front page displays’ is set to “A static page” and the “Front Page” value is the current Page being displayed.

    Michael

    (@alchymyth)

    it sounds as if ‘is_front_page()’ should work for you…

    Thread Starter kmcminn

    (@kmcminn)

    So, again I ask…does this look correct? I just want to make sure before I add it to the header.

    <meta name="description" content="<?php if( is_front_page() ) { ?>
      your meta description for the home page
    <?php } elseif ( is_single() ) {
      single_post_title();
    } else {
      bloginfo('name'); echo " - "; bloginfo('description');
    } ?>" />
    Michael

    (@alchymyth)

    it does look correct;

    you will get:
    your description text on the home page,
    the single post title on single posts,
    and otherwise ‘site title – site description’

    Thread Starter kmcminn

    (@kmcminn)

    OK, I added that and I’m getting this in the upper-left hand corner of the page.

    See image

    That’s what was happening before when I tried on my own before coming here for help.

    I added the code to the Header Code portion for my theme from the dashboard.

    kmessinger

    (@kmessinger)

    This " /> should not be in the above code.

    Thread Starter kmcminn

    (@kmcminn)

    @kmessinger

    That’s exactly what my thoughts are, hence my original concern about the example code on the official Codex page. If you look at it though, there’s got to be an end quote somewhere for the content description.

    Am I right?

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Meta Descriptions’ is closed to new replies.