Use add_rewrite_endpoint without the trailing slash
-
Using this function successfully per the code below. It creates an accessible permalink like domain.com/category/post/deals. However, what I need the permalink to render as is actually domain.com/category/post-deals (no trailer slash just “-deals”) but still have it accessible in the vars so I can load the proper template. Is there a way to do that with this function?
function wpd_add_deals(){ add_rewrite_endpoint( 'deals', EP_PERMALINK ); } add_action( 'init', 'wpd_add_deals' ); add_filter('request', function($vars) { if (isset($vars['deals'])) { $vars['deals'] = true; } return $vars; }); add_filter('template_include', function($template) { if (is_singular() && get_query_var('deals')) { $post = get_queried_object(); return locate_template(['my-template.php']); } return $template; });
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Use add_rewrite_endpoint without the trailing slash’ is closed to new replies.