Trailing Slash at the end of Posts links permalinks
-
Hi All,
I had to modify via function.php file the permalinks of my blogpost because If I do directly from the wordpress panel will change also my portofolio (galleries) links.
What I’m trying to get is a trailing slash at the end of all the links. Is there something that I can add or modigy in this code to achieve this? Thank you in advance!
I’m trying to achieve this without plugins thank you!Source Code /** * Rewrite WordPress URLs to Include /blog/ in Post Permalink Structure */ function _blog_generate_rewrite_rules( $wp_rewrite ) { $new_rules = array( '(([^/]+/)*blog)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[3]', 'blog/([^/]+)/?$' => 'index.php?post_type=post&name=$matches[1]', 'blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]', 'blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1', 'blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true', 'blog/[^/]+/embed/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true', 'blog/([^/]+)/embed/?$' => 'index.php?post_type=post&name=$matches[1]&embed=true', 'blog/[^/]+/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true', 'blog/([^/]+)/trackback/?$' => 'index.php?post_type=post&name=$matches[1]&tb=1', 'blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]', 'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]', 'blog/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged=$matches[1]', 'blog/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]', 'blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]', 'blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&cpage=$matches[2]', 'blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=post&name=$matches[1]&page=$matches[2]', 'blog/[^/]+/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]', 'blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1', 'blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]', ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_action( 'generate_rewrite_rules', '_blog_generate_rewrite_rules' ); function _blog_update_post_link( $post_link, $id = 0 ) { $post = get_post( $id ); if( is_object( $post ) && $post->post_type == 'post' ) { return home_url( '/blog/' . $post->post_name ); } return $post_link; } add_filter( 'post_link', '_blog_update_post_link', 1, 3 );
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Trailing Slash at the end of Posts links permalinks’ is closed to new replies.