create meta-data for homepage and individual posts. (2 posts)

  1. jalacom
    Posted 4 years ago #

    I'm trying to fix my meta-data so it plays nice with Facebook. I'm using Addthis and hardcoding it into my theme. I had a big blurb of meta-data that was on my homepage, this same page displays excerpts of the most recent posts.

    When you're on the homepage I want that blurb to be in the meta-data, and then when you're on a post I want the_excerpt to be used in the meta-data or the info from the excerpt field when creating a post (i'm not picky i'll take either that works best).

    I was trying to use this:

    <?php if ( (is_home() || is_front_page() ) ) { ?>
    <meta name="description" content="Blog info goes here" />
    <?php } elseif (is_single()) { ?>
    <meta name="description" content="<?php the_excerpt();?>"/>
    <?php } ?>

    Seems like it would work, but i keep getting an error on the first line of it. The way it's set up is how i would like it to function though. Look to make sure it's the homepage or front page, if so use that meta-data, if not and it's a single use the excerpt info from it for the meta-data. Not sure what i'm doing wrong. I should be able to replace "Blog info goes here" and be good to go. But like I said the first line is throwing the error.

    I've found this:

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

    And it's working,...except I can't get the meta-data from the homepage to show.
    here's my site: GTSB

    I keep making changes so i don't know if that will help. Also the home page is actually calling excerpts from category 5, because the page Brilliant is supposed to call excerpts from category 3 (essentially using it as a subblog). Not sure if that's contributing to the error or not.
    I have also included in my functions two functions for Facebook (not sure if both are necessary or not, or even effecting the problem i'm dealing with right now) one adds Open Graph to the language attributes like this:

    function add_opengraph_doctype( $output ) {
    		return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
    add_filter('language_attributes', 'add_opengraph_doctype');

    The other is too long to post but it converts content to Open graph info...I think. I got the function here wpbeginner

    Any help would be appreciated as I have very little hair left to pull.

  2. jalacom
    Posted 4 years ago #

    I know there's a lot of information to sift through but if anyone has some ideas I'm all ears. Thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic