Last update at :2023-12-31,Edit by888u
In addition to external links, the optimization of the program itself is also very important for seo optimization, and sometimes we tend to ignore this aspect. In a website built using WordPress, unless it is just for your own entertainment, you can leave it alone. For most people, they want to get everyone's attention. What I want to share with you today is how to optimize WordPress to add slashes to category directories and tag addresses. Generally speaking, the normal address of a directory should end with a slash, but WordPress does not have it by default, so there is a situation like "https://www.thissite.com/category/vps", which is very important for Search engines are not friendly, so if you find that the WordPress theme you are currently using does not have this feature, you can add it yourself and give it a try.
Add the following code to function.php to add a slash after the directory address of the category directory and tag label. This method is suitable for most situations.
- //Add a slash after the category directory address
- function nice_trailingslashit($string, $type_of_url) {
- if ( $type_of_url != ‘single’ && $type_of_url != ‘page’ )
- $string = trailingslashit($string);
- return $string;
- }
- add_filter(‘user_trailingslashit’, ‘nice_trailingslashit’, 10, 2);
If you use the WordPress external link to internal link link jump plug-in Simple URLs, there will be an inexplicable extra slash after the generated short link during use. You can change the following Add the code snippet to function.php. After saving the fixed link, the slash in the short link disappears, and the above code no longer needs to be used!
- //Add a slash after the category directory address
- if (is_admin()) return;
- $permalink_structure = get_option(‘permalink_structure’);
- if (!$permalink_structure || ‘/’ === substr($permalink_structure, –1))
- return;
- add_filter(‘user_trailingslashit’, ‘ppm_fixe_trailingslash’, 10, 2);
- function ppm_fixe_trailingslash($url, $type)
- {
- if (‘single’ === $type || ‘page’ === $type)
- return $url;
- return trailingslashit($url);
- }
Please make sure to back up the original file when making changes to prevent errors that cannot be recovered. The best way is to back up the entire site data before making changes. If the theme is upgraded after modification, it will disappear. At this time, you can just add it!
Recommended site searches: US host reviews, German servers, ASP host space, free cloud computer host permanent use, Taiwan host, Japanese server free, cm domain name registration, game high defense server, Hong Kong server, mainland China virtual host, < /p>
发表评论