Для начала устанавливаем плагин Advanced Custom Field.
Создаем группу полей "SEO". Внутри группы создаем два обычных текстовых поля Title и Description.
Выставляем правила отображения группы на страницах: Тип записи равно Страницы.
Далее в header Добавляем код:
Код
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="https://gmpg.org/xfn/11">
<?if( get_field('title') ){?>
<?$title = get_field('title');?>
<title><?=$title?></title>
<?} else {?>
<title><?php single_post_title(); ?></title>
<?}?>
<?$description = get_field('description');?>
<meta name="description" content="<?=$description?>">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.1.2/css/all.css">
<?php wp_head(); ?>
</head>
А в function.php добавляем это:
Код
/**
* Remove Title and Description
*/
remove_action('wp_head', '_wp_render_title_tag', 1);
Еще один вариант с проверкой находимся ли мы на странице категории.
Пример
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?if( get_field('title') ){?>
<?$title = get_field('title');?>
<title><?=$title?></title>
<?} else {?>
<?
if( is_product_category() ) {
?>
<title><?php woocommerce_page_title(); ?> - СвитерОк</title>
<?} else {?>
<title><?php single_post_title(); ?> - СвитерОк</title>
<?}?>
<?}?>
<?$description = get_field('description');?>
<meta name="description" content="<?=$description?>">
На всякий случай, если вдруг понадобится затирать весь description, то воспользуемся такой вот функцией, разместим ее в файле function.php.
Убрать description
function remove_meta_descriptions($html) {
$pattern = '/<meta name(.*)=(.*)"description"(.*)>/i';
$html = preg_replace($pattern, '', $html);
return $html;
}
function clean_meta_descriptions($html) {
ob_start('remove_meta_descriptions');
}
add_action('get_header', 'clean_meta_descriptions', 100);
add_action('wp_footer', function(){ ob_end_flush(); }, 100);