<meta name="Keywords" content="<?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?>" />
<meta name="keywords" content="<?php wp_title(); echo ' , '; bloginfo( 'name' ); ?>" />
<meta name="description" content="<?php wp_title(); echo ' | '; bloginfo( 'description' ); ?>" />
ทำให้เครื่องหมาย
>>
หายไป
<meta name="keywords" content="<?php wp_title(''); echo ' , '; bloginfo( 'name' ); ?>"/>
<meta name="description" content="<?php wp_title(''); echo ' | '; bloginfo( 'description' ); ?>"/>
“If this is a single post view, show the post title; if this is a multi-post view, show the blog name and description.”
<meta name="description" content="<?php if ( is_single() ) {
single_post_title('', true);
} else {
bloginfo('name'); echo " - "; bloginfo('description');
}
?>" />
อื่นๆ
<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php wp_title(); ?></title>
<title><?php if(is_home()) { echo bloginfo("name"); echo " | "; echo bloginfo("description"); } else { echo wp_title(" | ", false, right); echo bloginfo("name"); } ?></title>
อื่นๆ
<?php if (is_single() && in_category('1')) { ?>
<meta name="description" content="<?php the_title();?>"/>
<?php } ?>
<?php if is_single(array( 41,48,103,152 )) { ?>
<meta name="description" content="<?php the_title();?>"/>
<?php } ?>
<?php if (is_category()) {
$cat = get_query_var('cat');
$metacat= strip_tags(category_description($cat));?>
<meta name="description" content="<?php echo $metacat;?>"/>
<?php } ?>
excerpt show on meta
<?php if (is_single() || is_page() ) : if (have_posts() ) : while (have_posts() ) : the_post(); ?>
<meta name="description" content="<?php echo get_the_excerpt();?>">
<?php endwhile; endif; elseif (is_home() ): ?>
<meta name="description" content="<?php bloginfo('description'); ?>- AND ADD SOME MORE CONTENT HERE">
<?php endif; ?>
http://www.davidtiong.com/adding-meta-description-to-wordpress-pages-without-a-plugin/
หรือ
<?php
http://fransdejonge.com/2012/04/using-wordpress-excerpts-in-meta-description/
$desc;
if ( is_single() ) {
$desc = get_the_excerpt();
}
elseif ( is_page() ) {
$desc = get_the_excerpt();
}
elseif ( is_category() ) {
$desc = category_description();
}
elseif ( is_home() ) {
$desc = get_bloginfo('description');
}
$desc = htmlspecialchars(trim(strip_tags($desc)));
if (!empty($desc)) {
echo '<meta name="description" content="';
echo $desc;
echo '"/>';
}
?>
<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php the_excerpt_rss(); ?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>
หรือ
<?php
if (is_singular()):
global $post;
setup_postdata($post);
?>
<meta name=”description” content=”<?php the_excerpt_rss(); ?>” />
<?php endif; ?>
ใช้คู่กับ
functions.php
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
Control Excerpt Length using Filters
By default, excerpt length is set to 55 words. To change excerpt length to 20 words using excerpt_length filter, add the following code to functions.php file in your theme
https://codex.wordpress.org/Function_Reference/the_excerpt