Opened 15 years ago
Closed 15 years ago
#4652 closed defect (bug) (duplicate)
Page and category trailing back-slash dependent on post permalink structure
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | high | |
Severity: | major | Version: | 2.2 |
Component: | General | Keywords: | wp_rewrite |
Focuses: | Cc: |
Description
If specifying a post permalink structure like this:
/article/%postname%.html
Then WP_Rewrite will discover that there is no ending back-slash and will set use_trailing_slashes to false.
Whenever creating links to categories og pages then it will now remove the ending back-slash.
This changes all category and page links when upgrading from 2.0 to 2.2, with duplicate content to follow.
The quick patch to this problem is to create a plugin with the following lines:
<?php function fix_trailing_backslash() { global $wp_rewrite; $wp_rewrite->use_trailing_slashes = true; } function fix_trailing_backslash_post( $link ) { global $wp_rewrite; if (!substr($wp_rewrite->permalink_structure, -1, 1) == '/' )) return rtrim( $link, '/' ); return $link; } add_action('init', 'fix_trailing_backslash'); add_filter('post_link', 'fix_trailing_backslash_post' ); ?>
Change History (6)
#2
@
15 years ago
The wrong parantes ofcourse, hopefully the final fix now :)
<?php function fix_trailing_backslash() { global $wp_rewrite; $wp_rewrite->use_trailing_slashes = true; } function fix_trailing_backslash_post( $link ) { global $wp_rewrite; if (! (substr($wp_rewrite->permalink_structure, -1, 1) == '/') ) return rtrim( $link, '/' ); return $link; } add_action('init', 'fix_trailing_backslash'); add_filter('post_link', 'fix_trailing_backslash_post' ); ?>
#3
@
15 years ago
Ok just discovered that user_trailingslashit has a nice filter also, much prettier plugin now:
<?php function fix_slash($string, $type) { global $wp_rewrite; if ($wp_rewrite->use_trailing_slashes==false && $type != 'single') return trailingslashit($string); return $string; } add_filter('user_trailingslashit', 'fix_slash', 66, 2 ); ?>
#5
@
15 years ago
It is dup of #3899.
Apparently the solution to this issue is writting a plugin (like the one I posted after a few attempts). Guess the install guidelines for WP 2.2 should be updated, so one is made aware of the change in Permalink-links and that one should install a plugin if using a post permalink structure without trailing slash.
Ofcourse I have to make an error in the plugin code :)