2014-06-21 4 views
1

С помощью ответа, полученного в Place category_description in the meta description (wordpress) Я думаю, что у меня это почти выяснено, но он просто не работает - когда я просматриваю источник страницы для любой страницы, мета-описание пусто:Мета-описание

<meta name="description" content="" /> 

Вот что я получил:

В functions.php

<?php 
if(is_single() || is_page()) $description = get_the_excerpt(); 
elseif(is_category()) $description = category_description(); 
else $description = "Free French lessons and language tools from Laura K. Lawless, including verb conjugations and bilingual articles to help you improve your reading and listening comprehension."; 
$description = substr($description,0,500); 
?> 

В заголовке

<meta name="description" content="<?= $description ?>" /> 

Любые идеи? ТИА!

ответ

2

Попробуйте эту функцию, она вернет что-то в большинстве случаев.

// functions.php 
function blog_description() { 
    $content = get_queried_object(); 

    if (is_singular()) { 
     $content = !empty($content->post_excerpt) ? $content->post_excerpt : (!empty($content->post_content) ? $content->post_content : $content->post_title); 
     return str_replace(PHP_EOL, ' ', substr(wp_filter_nohtml_kses($content), 0, 155)); 

    } elseif (is_category()) {   
     $content = !empty($content->description) ? $content->description : get_bloginfo('name') . ' - ' . $content->name;  
     return str_replace(PHP_EOL, ' ', substr(wp_filter_nohtml_kses($content), 0, 155));  
    } 

    return get_bloginfo('description'); 
} 

// header.php 
<meta name="description" content="<?php echo blog_description(); ?>" /> 
Смежные вопросы