src/Util/Theme.php
public static function pageTitle() {
    $short_site_name = Config::get()->site_name;
    $separator = self::pageTitleSeparator();
    $title = wp_title(null, false);
    
    // From an SEO/SEM perspective, appending the site name to the title is
    // superfluous if the title already contains some form of the site name, as
    // may be the case with press releases and other news-related posts
    $title_has_site_name = (strpos($title, $short_site_name) !== false);
    if(!empty($title) && $title_has_site_name) {
      return $title;
    }
    
    $site_name = get_bloginfo('name');
    if(!empty($title)) {
      return $title.$separator.$site_name;
    }
    
    global $post;
    $this_post = $post;
    
    // Create Taco post only if $post is not already a Taco object
    if(!is_subclass_of($post, 'Taco\Base')) {
      $this_post = \Taco\Post\Factory::create($post);
    }
    
    $page_title_taxonomy = $this_post->pageTitleTaxonomy();
    
    if(Config::get()->use_yoast) {
      $yoast_title = $this_post->getSafe('_yoast_wpseo_title');
      $yoast_title_has_site_name = preg_match('/'.$site_name.'$/', $yoast_title);
      if(!empty($yoast_title) && $yoast_title_has_site_name) {
        return $yoast_title;
      }
      
      if(!empty($yoast_title)) {
        return $yoast_title.$separator.$site_name;
      }
    }
    
    if(empty($page_title_taxonomy)) {
      return $this_post->getTheTitle().$separator.$site_name;
    }
    
    $term_name = null;
    $terms = $this_post->getTerms($page_title_taxonomy);
    if(!empty($terms)) {
      $primary_term_id = $this_post->{'_yoast_wpseo_primary_'.$page_title_taxonomy};
      $term = (!empty($primary_term_id))
        ? $terms[$primary_term_id]
        : reset($terms);
      $term_name = $separator.$term->name;
    }
    return $this_post->getTheTitle().$term_name.$separator.$site_name;
  }
public static function pageTitle() {
    $short_site_name = Config::get()->site_name;
    $separator = self::pageTitleSeparator();
    $title = wp_title(null, false);
    
    // From an SEO/SEM perspective, appending the site name to the title is
    // superfluous if the title already contains some form of the site name, as
    // may be the case with press releases and other news-related posts
    $title_has_site_name = (strpos($title, $short_site_name) !== false);
    if(!empty($title) && $title_has_site_name) {
      return $title;
    }
    
    $site_name = get_bloginfo('name');
    if(!empty($title)) {
      return $title.$separator.$site_name;
    }
    
    global $post;
    $this_post = $post;
    
    // Create Taco post only if $post is not already a Taco object
    if(!is_subclass_of($post, 'Taco\Base')) {
      $this_post = \Taco\Post\Factory::create($post);
    }
    
    $page_title_taxonomy = $this_post->pageTitleTaxonomy();
    
    if(Config::get()->use_yoast) {
      $yoast_title = $this_post->getSafe('_yoast_wpseo_title');
      $yoast_title_has_site_name = preg_match('/'.$site_name.'$/', $yoast_title);
      if(!empty($yoast_title) && $yoast_title_has_site_name) {
        return $yoast_title;
      }
      
      if(!empty($yoast_title)) {
        return $yoast_title.$separator.$site_name;
      }
    }
    
    if(empty($page_title_taxonomy)) {
      return $this_post->getTheTitle().$separator.$site_name;
    }
    
    $term_name = null;
    $terms = $this_post->getTerms($page_title_taxonomy);
    if(!empty($terms)) {
      $primary_term_id = $this_post->{'_yoast_wpseo_primary_'.$page_title_taxonomy};
      $term = (!empty($primary_term_id))
        ? $terms[$primary_term_id]
        : reset($terms);
      $term_name = $separator.$term->name;
    }
    return $this_post->getTheTitle().$term_name.$separator.$site_name;
  }
public static function pageTitle ( ) { $ short_site_name = Config :: get ( ) -> site_name ; $ separator = self :: pageTitleSeparator ( ) ; $ title = wp_title ( null , false ) ; // From an SEO/SEM perspective, appending the site name to the title is // superfluous if the title already contains some form of the site name, as // may be the case with press releases and other news-related posts $ title_has_site_name = ( strpos ( $ title , $ short_site_name ) !== false ) ; if ( ! empty ( $ title ) && $ title_has_site_name ) { return $ title ; } $ site_name = get_bloginfo ( 'name' ) ; if ( ! empty ( $ title ) ) { return $ title . $ separator . $ site_name ; } global $ post ; $ this_post = $ post ; // Create Taco post only if $post is not already a Taco object if ( ! is_subclass_of ( $ post , 'Taco\Base' ) ) { $ this_post = \ Taco \ Post \ Factory :: create ( $ post ) ; } $ page_title_taxonomy = $ this_post -> pageTitleTaxonomy ( ) ; if ( Config :: get ( ) -> use_yoast ) { $ yoast_title = $ this_post -> getSafe ( '_yoast_wpseo_title' ) ; $ yoast_title_has_site_name = preg_match ( '/' . $ site_name . '$/' , $ yoast_title ) ; if ( ! empty ( $ yoast_title ) && $ yoast_title_has_site_name ) { return $ yoast_title ; } if ( ! empty ( $ yoast_title ) ) { return $ yoast_title . $ separator . $ site_name ; } } if ( empty ( $ page_title_taxonomy ) ) { return $ this_post -> getTheTitle ( ) . $ separator . $ site_name ; } $ term_name = null ; $ terms = $ this_post -> getTerms ( $ page_title_taxonomy ) ; if ( ! empty ( $ terms ) ) { $ primary_term_id = $ this_post -> { '_yoast_wpseo_primary_' . $ page_title_taxonomy } ; $ term = ( ! empty ( $ primary_term_id ) ) ? $ terms [ $ primary_term_id ] : reset ( $ terms ) ; $ term_name = $ separator . $ term -> name ; } return $ this_post -> getTheTitle ( ) . $ term_name . $ separator . $ site_name ; }
Get the page title
@return string
Get the page title