A
A
Alisa Sokolova2020-12-01 14:54:15
Search Engine Optimization
Alisa Sokolova, 2020-12-01 14:54:15

How to template meta tags for product pages and home page in Yoast SEO?

Colleagues, please tell me how to register separate meta tags for the main page of an online store in the Yoast SEO plugin (using woocoomerce). And how to make an automatic template of meta tags with product name support on product pages?

PS If I understood correctly, then in

SEO > Display in SERPs > Main page: SEO title
responds to the meta tags of the main page.
SZW_jwiV8JQ.jpg?size=867x393&quality=96&proxy=1&sign=b3b0e5ebd05777aca01d83d09cf38d41

But, where is the template for products configured?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2020-12-02
@Alisa_Sokolova

You can create your own variables for yoast. Here are some examples:

function get_seo_instead_title() {
  if ( is_single() ) {
    if ( get_post_type() === 'route' ) {
      $roads_subtype = get_post_meta(get_the_ID(), 'subtype', true );
      if ( $roads_subtype == 'bus' ) {
        return 'Расписание автобусов ' . get_the_title();
      } else {
        return 'Расписание маршрутов ' . get_the_title();
      }
    }
  }
}

function get_seo_before_title() {
  if ( is_tax() ) {
    if ( is_tax( 'routes' ) ) {
      return 'Справочник маршрутов города ';
    }
  }
}

function get_seo_after_title() {
  if ( is_single() ) {
    if ( get_post_type() === 'platform' ) {
      return ' — маршруты и расписание транспорта';
    }
  }
}

// %%BeforeTitle%% %%title%% %%AfterTitle%%
// %%BeforeTitle%% %%term_title%% %%AfterTitle%%

// define the action for register yoast_variable replacments
function register_custom_yoast_variables() {
  wpseo_register_var_replacement( '%%BeforeTitle%%', 'get_seo_before_title', 'advanced', 'Some before title text' );
  wpseo_register_var_replacement( '%%AfterTitle%%', 'get_seo_after_title', 'advanced', 'Some after title text' );
  wpseo_register_var_replacement( '%%InsteadTitle%%', 'get_seo_instead_title', 'advanced', 'Some instead title text' );
}

// Add action
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');

As you can see, the $post variable is defined, so all functions like get_the_ID(), get_the_title(), get_post_meta()etc. work. Common templates are in the adjacent tabs of the screenshot you are showing - Content Types and Taxonomies

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question