WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Not working: if is_page() (4 posts)

  1. rtomo
    Member
    Posted 1 year ago #

    Hey!

    I'm trying add header facebook og:title for my theme.

    That's the code:

    add_action( 'wp_head', 'rotisoft_meta_cim' );
    function rotisoft_meta_cim()
    {
    	echo '<meta property="og:title" content="';
    
    if ( is_page('117') ) {
    
    	echo "Blog Site Title";
    }
    
    elseif ( is_front_page() ) {
    
        bloginfo( 'name' );
    	echo " | MySyite description";
    } 
    
    elseif ( is_page() ) {
    
    	echo "MySite | ";
    	echo get_the_title();
    
    } elseif ( is_category() ) {
    
    	echo "Mysite Category: ";
    	single_cat_title();
    
    } elseif ( is_tag() ) {
    
    	echo "MySite tag: ";
    	single_tag_title('');
    
    } elseif ( is_single() ) {
    
        bloginfo( 'name' );
    	echo " | ";
    	the_title();
    
    } else {
    
        bloginfo( 'name' );
    	echo " | ";
    	the_title();
    
    }
    	echo '">' . "\n" ;
    }

    The problem: When i'm look the 117 id's site, the title is the latest blog post title. (Don't the _Blog Site Title_.)

    I'm testing thats codes:
    if ( is_page(117,'blog','Blog') )

    I'm read that page: http://codex.wordpress.org/Function_Reference/is_page
    But, i'm don't know, what is the problem. :(

    Thx for help!

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try using is_page() once:

    add_action( 'wp_head', 'rotisoft_meta_cim' );
    function rotisoft_meta_cim()
    {
    	echo '<meta property="og:title" content="';
    
    if ( is_page() ) {
      if ( is_page('117') ) {
    	echo "Blog Site Title";
      } else {
        echo "MySite | ";
        echo get_the_title();
      }
    }
    
    elseif ( is_front_page() ) {
    
        bloginfo( 'name' );
    	echo " | MySyite description";
    }
    elseif ( is_category() ) {
    
    	echo "Mysite Category: ";
    	single_cat_title();
    
    } elseif ( is_tag() ) {
    
    	echo "MySite tag: ";
    	single_tag_title('');
    
    } elseif ( is_single() ) {
    
        bloginfo( 'name' );
    	echo " | ";
    	the_title();
    
    } else {
    
        bloginfo( 'name' );
    	echo " | ";
    	the_title();
    
    }
    	echo '">' . "\n" ;
    }
  3. alchymyth
    Forum Moderator
    Posted 1 year ago #

    if you are targeting the 'posts page', i.e. the page that you have set to show the latest posts, try to use:

    is_home()

    http://codex.wordpress.org/Conditional_Tags#The_Main_Page

  4. rtomo
    Member
    Posted 1 year ago #

    @keesiemeijer: not working. =/

    I'm trying with the theme framework costum fields, and it solved the problem.

Topic Closed

This topic has been closed to new replies.

About this Topic