get_custom_title() public static method

Used to modify the default title with custom SEO title.
public static get_custom_title ( string $default_title = '' ) : string
$default_title string Default title for current page.
return string Custom title with replaced tokens or default title.
Example #1
0
 public function meta_tags()
 {
     global $wp_query;
     $period = '';
     $template = '';
     $meta = array();
     /**
      * Can be used to specify a list of themes that set their own meta tags.
      *
      * If current site is using one of the themes listed as conflicting, inserting Jetpack SEO
      * meta tags will be prevented.
      *
      * @module seo-tools
      *
      * @since 4.4.0
      *
      * @param array List of conflicted theme names. Defaults to empty array.
      */
     $conflicted_themes = apply_filters('jetpack_seo_meta_tags_conflicted_themes', array());
     if (isset($conflicted_themes[get_option('template')])) {
         return;
     }
     /**
      * Can be used to insert custom site host that will used for meta title.
      *
      * @module seo-tools
      *
      * @since 4.4.0
      *
      * @param string Name of the site host. Defaults to empty string.
      */
     $site_host = apply_filters('jetpack_seo_site_host', '');
     $meta['title'] = sprintf(_x('%1$s', 'Site Title', 'jetpack'), get_bloginfo('title'));
     if (!empty($site_host)) {
         $meta['title'] = sprintf(_x('%1$s on %2$s', 'Site Title on WordPress', 'jetpack'), get_bloginfo('title'), $site_host);
     }
     $front_page_meta = Jetpack_SEO_Utils::get_front_page_meta_description();
     $description = $front_page_meta ? $front_page_meta : get_bloginfo('description');
     $meta['description'] = trim($description);
     // Try to target things if we're on a "specific" page of any kind.
     if (is_singular()) {
         $meta['title'] = sprintf(_x('%1$s | %2$s', 'Post Title | Site Title on WordPress', 'jetpack'), get_the_title(), $meta['title']);
         // Business users can overwrite the description.
         if (!(is_front_page() && Jetpack_SEO_Utils::get_front_page_meta_description())) {
             $description = Jetpack_SEO_Posts::get_post_description(get_post());
             if ($description) {
                 $description = wp_trim_words(strip_shortcodes(wp_kses($description, array())));
                 $meta['description'] = $description;
             }
         }
     } elseif (is_author()) {
         $obj = get_queried_object();
         $meta['title'] = sprintf(_x('Posts by %1$s | %2$s', 'Posts by Author Name | Blog Title on WordPress', 'jetpack'), $obj->display_name, $meta['title']);
         $meta['description'] = sprintf(_x('Read all of the posts by %1$s on %2$s', 'Read all of the posts by Author Name on Blog Title', 'jetpack'), $obj->display_name, get_bloginfo('title'));
     } elseif (is_tag() || is_category() || is_tax()) {
         $obj = get_queried_object();
         $meta['title'] = sprintf(_x('Posts about %1$s on %2$s', 'Posts about Category on Blog Title', 'jetpack'), single_term_title('', false), get_bloginfo('title'));
         $description = get_term_field('description', $obj->term_id, $obj->taxonomy, 'raw');
         if (!is_wp_error($description) && '' != $description) {
             $meta['description'] = wp_trim_words($description);
         } else {
             $authors = $this->get_authors();
             $meta['description'] = wp_sprintf(_x('Posts about %1$s written by %2$l', 'Posts about Category written by John and Bob', 'jetpack'), single_term_title('', false), $authors);
         }
     } elseif (is_date()) {
         if (is_year()) {
             $period = get_query_var('year');
             $template = _nx('%1$s post published by %2$l in the year %3$s', '%1$s posts published by %2$l in the year %3$s', count($wp_query->posts), '10 posts published by John in the year 2012', 'jetpack');
         } elseif (is_month()) {
             $period = date('F Y', mktime(0, 0, 0, get_query_var('monthnum'), 1, get_query_var('year')));
             $template = _nx('%1$s post published by %2$l during %3$s', '%1$s posts published by %2$l during %3$s', count($wp_query->posts), '10 posts publishes by John during May 2012', 'jetpack');
         } elseif (is_day()) {
             $period = date('F j, Y', mktime(0, 0, 0, get_query_var('monthnum'), get_query_var('day'), get_query_var('year')));
             $template = _nx('%1$s post published by %2$l on %3$s', '%1$s posts published by %2$l on %3$s', count($wp_query->posts), '10 posts published by John on May 30, 2012', 'jetpack');
         }
         $meta['title'] = sprintf(_x('Posts from %1$s on %2$s', 'Posts from May 2012 on Blog Title', 'jetpack'), $period, get_bloginfo('title'));
         $authors = $this->get_authors();
         $meta['description'] = wp_sprintf($template, count($wp_query->posts), $authors, $period);
     }
     $custom_title = Jetpack_SEO_Titles::get_custom_title();
     if (!empty($custom_title)) {
         $meta['title'] = $custom_title;
     }
     /**
      * Can be used to edit the default SEO tools meta tags.
      *
      * @module seo-tools
      *
      * @since 4.4.0
      *
      * @param array Array that consists of meta name and meta content pairs.
      */
     $meta = apply_filters('jetpack_seo_meta_tags', $meta);
     // Output them
     foreach ($meta as $name => $content) {
         if (!empty($content)) {
             echo '<meta name="' . esc_attr($name) . '" content="' . esc_attr($content) . '" />' . "\n";
         }
     }
 }