/**
  * Get Home URL
  *
  * This has been moved from the constructor because wp_rewrite is not available on plugins_loaded in multisite.
  * It will now be requested on need and not on initialization.
  *
  * @return string
  */
 protected function get_home_url()
 {
     if (!isset(self::$home_url)) {
         self::$home_url = WPSEO_Utils::home_url();
     }
     return self::$home_url;
 }
 /**
  * Get Home URL
  *
  * This has been moved from the constructor because wp_rewrite is not available on plugins_loaded in multisite.
  * It will now be requested on need and not on initialization.
  *
  * @return string
  */
 protected function get_home_url()
 {
     if (!isset($this->home_url)) {
         $this->home_url = WPSEO_Utils::home_url();
     }
     return $this->home_url;
 }
Exemple #3
0
 /**
  * Retrieves the home URL
  *
  * @return string
  */
 private function get_home_url()
 {
     /**
      * Filter: 'wpseo_json_home_url' - Allows filtering of the home URL for Yoast SEO's JSON+LD output
      *
      * @api unsigned string
      */
     return apply_filters('wpseo_json_home_url', WPSEO_Utils::home_url());
 }
 /**
  * This function normally outputs the canonical but is also used in other places to retrieve
  * the canonical URL for the current page.
  *
  * @return void
  */
 private function generate_canonical()
 {
     $canonical = false;
     $canonical_override = false;
     // Set decent canonicals for homepage, singulars and taxonomy pages.
     if (is_singular()) {
         $obj = get_queried_object();
         $canonical = get_permalink($obj->ID);
         $this->canonical_unpaged = $canonical;
         $canonical_override = WPSEO_Meta::get_value('canonical');
         // Fix paginated pages canonical, but only if the page is truly paginated.
         if (get_query_var('page') > 1) {
             $num_pages = substr_count($obj->post_content, '<!--nextpage-->') + 1;
             if ($num_pages && get_query_var('page') <= $num_pages) {
                 if (!$GLOBALS['wp_rewrite']->using_permalinks()) {
                     $canonical = add_query_arg('page', get_query_var('page'), $canonical);
                 } else {
                     $canonical = user_trailingslashit(trailingslashit($canonical) . get_query_var('page'));
                 }
             }
         }
     } else {
         if (is_search()) {
             $search_query = get_search_query();
             // Regex catches case when /search/page/N without search term is itself mistaken for search term. R.
             if (!empty($search_query) && !preg_match('|^page/\\d+$|', $search_query)) {
                 $canonical = get_search_link();
             }
         } elseif (is_front_page()) {
             $canonical = WPSEO_Utils::home_url();
         } elseif ($this->is_posts_page()) {
             $posts_page_id = get_option('page_for_posts');
             $canonical = WPSEO_Meta::get_value('canonical', $posts_page_id);
             if (empty($canonical)) {
                 $canonical = get_permalink($posts_page_id);
             }
         } elseif (is_tax() || is_tag() || is_category()) {
             $term = get_queried_object();
             if (!empty($term) && !$this->is_multiple_terms_query()) {
                 $canonical_override = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'canonical');
                 $term_link = get_term_link($term, $term->taxonomy);
                 if (!is_wp_error($term_link)) {
                     $canonical = $term_link;
                 }
             }
         } elseif (is_post_type_archive()) {
             $post_type = get_query_var('post_type');
             if (is_array($post_type)) {
                 $post_type = reset($post_type);
             }
             $canonical = get_post_type_archive_link($post_type);
         } elseif (is_author()) {
             $canonical = get_author_posts_url(get_query_var('author'), get_query_var('author_name'));
         } elseif (is_archive()) {
             if (is_date()) {
                 if (is_day()) {
                     $canonical = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'));
                 } elseif (is_month()) {
                     $canonical = get_month_link(get_query_var('year'), get_query_var('monthnum'));
                 } elseif (is_year()) {
                     $canonical = get_year_link(get_query_var('year'));
                 }
             }
         }
         $this->canonical_unpaged = $canonical;
         if ($canonical && get_query_var('paged') > 1) {
             global $wp_rewrite;
             if (!$wp_rewrite->using_permalinks()) {
                 if (is_front_page()) {
                     $canonical = trailingslashit($canonical);
                 }
                 $canonical = add_query_arg('paged', get_query_var('paged'), $canonical);
             } else {
                 if (is_front_page()) {
                     $canonical = WPSEO_Sitemaps_Router::get_base_url('');
                 }
                 $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged'));
             }
         }
     }
     $this->canonical_no_override = $canonical;
     if (is_string($canonical) && $canonical !== '') {
         // Force canonical links to be absolute, relative is NOT an option.
         if (WPSEO_Utils::is_url_relative($canonical) === true) {
             $canonical = $this->base_url($canonical);
         }
     }
     if (is_string($canonical_override) && $canonical_override !== '') {
         $canonical = $canonical_override;
     }
     /**
      * Filter: 'wpseo_canonical' - Allow filtering of the canonical URL put out by Yoast SEO
      *
      * @api string $canonical The canonical URL
      */
     $this->canonical = apply_filters('wpseo_canonical', $canonical);
 }
Exemple #5
0
 /**
  * Add Homepage crumb to the crumbs property
  */
 private function add_home_crumb()
 {
     $this->add_predefined_crumb($this->options['breadcrumbs-home'], WPSEO_Utils::home_url(), true);
 }