5个代码片段改善SEO优化排名

WordPress   2024年05月02日 2:05  

1. 404重定向页面

< IfModule mod_alias.c >RedirectMatch 301 ^/search/$ http://your-site.com/RedirectMatch 301 ^/tag/$ http://your-site.com/RedirectMatch 301 ^/category/$ http://your-site.com/< /IfModule >

404错误页面是这些页面产生当没有网页内容所指定的。坏的部分是,404页,404页减少你的博客的Pagerank使你的站点排名无效。所以,我们将致力于改善SEO是利用WordPress Hack 404错误页面的重定向到博客的主页。

2.自动从URL中删除停止词

add_filter('sanitize_title', 'remove_short_words');function remove_short_words($slug) {if (!is_admin()) return $slug;$slug = explode('-', $slug);foreach ($slug as $k => $word) {if (strlen($word) < 3) {unset($slug[$k]);}}return implode('-', $slug);}

当你写博客文章的在WordPress,根据永久链接调整你写的。人们认为我们不应该停止的话,像对,,等的博客文章的永久链接。它提高了搜索引擎优化,还有助于期望从URL的内容只。所以,为了使工作自动完成,使用代码片段来自动删除stop单词从永久链接来提高SEO。

3.突出关键字在搜寻结果

function wps_highlight_results($text){if(is_search()){$sr = get_query_var('s');$keys = explode(" ",$sr);$text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong>'.$sr.'</strong>', $text);}return $text;}add_filter('the_excerpt', 'wps_highlight_results');add_filter('the_title', 'wps_highlight_results');

使用此代码段突出显示搜索词在你的博客搜索结果the_excerpt和the_title。

4.改写搜索结果的永久链接

function search_url_rewrite_rule() {if ( is_search() && !empty($_GET['s'])) {wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));exit();}}add_action('template_redirect', 'search_url_rewrite_rule');

这个片段可以帮助你像“yourblog.com/搜索/搜索关键字”的搜索结果永久改写,最终其比默认搜索永久性的更好,从而提高搜索引擎优化。

5.谷歌机器人的禁止目录

User-agent: GooglebotAllow: /?display=wideDisallow: /wp-content/Disallow: /trackback/Disallow: /wp-admin/Disallow: /feed/Disallow: /index.phpDisallow: /*?Disallow: /*.js$Disallow: /*.inc$Disallow: /*.css$Disallow: */feed/Disallow: */trackback/Disallow: /link.phpDisallow: /gallery2Disallow: /gallery2/Disallow: /refer/User-agent: Googlebot-ImageDisallow: /wp-includes/User-agent: Mediapartners-Google*Disallow:

使用这段代码片段在你的机器人,txt文件来防止Gogole机器人能像wp-content指数不期望的目录,wp-includes等等。

域名注册
购买VPS主机

您或许对下面这些文章有兴趣:                    本月吐槽辛苦排行榜

看贴要回贴有N种理由!看帖不回贴的后果你懂得的!


评论内容 (*必填):
(Ctrl + Enter提交)   

部落快速搜索栏

各类专题梳理

网站导航栏

X
返回顶部