k-isabelle
5/31/2018 - 4:29 PM

Wordpress Title / Display Page Parent in Title

Wordpress Title / Display Page Parent in Title

// Default Title

<title><?php wp_title( '|', true, 'right' ); ?></title>


// Display Page Parent in Title

    <title>
      <?php
      if($post->post_parent) {
      $parent_title = get_the_title($post->post_parent);
      echo $parent_title.' - ';
      } ?> 
      <?php wp_title( '|', true, 'right' ); ?>
    </title>

// source: http://www.tammyhartdesigns.com/tutorials/wordpress-how-to-display-the-parent-page-title-in-your-title-meta-tag/


// A title for any situation

<title>
  <?php
    $sep = ' | ';

    if (is_category()) {
      echo 'Category: '; wp_title(''); echo $sep;

    } elseif (function_exists('is_tag') && is_tag()) {
      single_tag_title('Tag Archive for &quot;'); echo '&quot;' . $sep;

    } elseif (is_archive()) {
      wp_title(''); echo ' Archive' . $sep;

    } elseif (is_home()) {
      echo wp_title(''); echo $sep;

    } elseif (is_front_page()) {
      echo '';

    } elseif (is_page()) {
      echo wp_title(''); echo $sep;

    } elseif (is_search()) {
      echo 'Search for &quot;'.wp_specialchars($s).'&quot;' . $sep;

    } elseif (!(is_404()) && (is_single()) || (is_page())) {
      wp_title(''); echo $sep;

    } elseif (is_404()) {
      echo 'Not Found' . $sep;

    } bloginfo('name');
  ?>
</title>