I'm trying to configure my Facebook Og meta tags in my header so I get a different result on the type of page I want. I've been hitting some road block that searching through google haven't been able to resolve, so I thought asking for help here.

This question comes in two parts, one about if statements and wordpress conditional tags. The second about the use of get_the_excerpt with those if statements.

Here I'm trying to set the default title. But I'm suspecting my issues are linked to my if statements.

<meta property="og:title" content="<?php if( is_single() || is_page()){ 
echo get_the_title(); //for post and pages
}else{ if( is_home() || is_front_page() ){
echo "Predefined Name";  //force the name as default for the home / front page
echo wp_title //to get default title for all other types of pages
?>" />

For the page description i'm unsuccessfully also trying to get the excerpt using get_the_excerpt, but since i'm outside the loop, it doesn't work. I've been looking especially here (Get excerpt using get_the_excerpt outside a loop) for help, but I'm not sure as to how to incorporate those.

    <meta property="og:description" content="<?php if (is_single() ){
        echo get_the_excerpt //to get the post's excerpt from outside the loop
    }else{ if( is_home() || is_front_page() ){
    echo "Predefined Description";  //doing this to force a default description
        echo "Predefined Description"; //for all other pages
    } ?>" />
  • use the_post(); just before the get_the_excerpt() function. – Sisir Sep 18 '14 at 16:05
  • @sisir If you wanna post a solution I can vote it, but the question also revolves around the if statements, if you wanna offer your input on those too in the answer it could be helpful! – user51030 Sep 22 '14 at 2:40

looks like your elseif statement isn't correct. try something like :

if ( is_single() || is_page() ) {
echo get_the_title();
} elseif ( is_home() || is_front_page() ) {
echo "Predefined Name";
} else {
echo wp_title;


Not the answer you're looking for? Browse other questions tagged or ask your own question.