WordPress tips: how to add a slash (/) to the end of a list URL, such as a category or Tag

Source: Internet
Author: User
What makes WordPress powerful is that what we can think of has been implemented, but we don't know. There are many solutions on the internet, basically classified as: 1. through RewriteRule301 jump implementation (if it is included in the URL can be, but at the beginning is not recommended to use) 2. implemented by modifying the wp-includescanonical.php

What makes WordPress powerful is that what we can think of has been implemented, but we don't know. There are many solutions on the internet, basically classified as: 1. use Rewrite Rule 301 to redirect (if the URL is included, but it is not recommended at the beginning. by modifying wp-includes/canonical. php implementation (will be

What makes WordPress powerful is that what we can think of has been implemented, but we don't know.

There are many solutions on the internet, basically classified:
1. Implement the redirection through Rewrite Rule 301 (if the URL is included, it is acceptable, but it is not recommended at the beginning)
2. implement this by modifying wp-receivdes/canonical. php (this will be overwritten during the upgrade and is not recommended)
3. Implemented through plug-ins

The following describes the plug-in method:
The plug-in Permalink Trailing Slash Fixer has implemented this function.

After downloading the code, you will find that there are only a few lines. In addition, the built-in Wordpress method is used internally. And no 301 jump occurs. I personally think it is an ideal solution.

The Code is as follows:

/** * Public staff only. */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);/** * Appends a trailing slash if it's missing in the permalink structure. * * Conditionally adds a trailing slash if the url type is not "single". * * @param string $url A URL with or without a trailing slash. * @param string $type The type of URL being considered (e.g. single, category, etc). * @return string The URL with the trailing slash fixed. */function ppm_fixe_trailingslash($url, $type){if ('single' === $type)return $url;return trailingslashit($url);}

Is it concise .....

If you are using multiple sites, and the previous site SEO is not bad, now you are ready to add a new site, in case of mutual impact, it is recommended that you fine-tune the above Code and add it to the template directory functoins. php (or use the plug-in to open an account only on a new site ):

if (!is_admin()) {    function ppm_fixe_trailingslash($url, $type)    {        $permalink_structure = get_option('permalink_structure');        if (!$permalink_structure || '/' === substr($permalink_structure, -1))        {        return;        }        if ('single' === $type || 'page' === $type)        {        return $url;        }        return trailingslashit($url);    }    add_filter('user_trailingslashit', 'ppm_fixe_trailingslash', 10, 2);}

Finally, the most important thing is to make the newly added URL Rules take effect: Enter the background-> Setting-> Permalinks refresh.

Original article address: WordPress tips: how to add a slash (/) to the end of a list URL such as classification and Tag ?, Thanks to the original author.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.