WordPress有很多SEO插件來幫助進行搜索引擎優化。如果你不想使用插件,下面這個高效的代碼,將使你的博客對搜索引擎更加友好。
將下面代碼粘貼到你的functions.php文件:
- function basic_wp_seo() {
- global $page, $paged, $post;
- $default_keywords = 'wordpress, plugins, themes, design, dev, development, security, htaccess, apache, php, sql, html, css, jquery, javascript, tutorials'; // customize
- $output = '';
-
- // description
- $seo_desc = get_post_meta($post->ID, 'mm_seo_desc', true);
- $description = get_bloginfo('description', 'display');
- $pagedata = get_post($post->ID);
- if (is_singular()) {
- if (!empty($seo_desc)) {
- $content = $seo_desc;
- } else if (!empty($pagedata)) {
- $content = apply_filters('the_excerpt_rss', $pagedata->post_content);
- $content = substr(trim(strip_tags($content)), 0, 155);
- $content = preg_replace('#\n#', ' ', $content);
- $content = preg_replace('#\s{2,}#', ' ', $content);
- $content = trim($content);
- }
- } else {
- $content = $description;