Open vwasteels opened 11 years ago
$router = WP_Router::get_instance();
if ( $router->get_route('my_custom_routing') !== NULL ) { echo 'menu-active'; }
But you're right, there should be a template tag for that.
I tried using your method as
$router = WP_Router::get_instance();
if ( $router->get_route('help-route-id') !== NULL ) { echo 'Help section'; }
but "Help section" is output on to every page, not only the only ones routed through "help-route-id". This happened when placing the above code in either header.php or page.php.
Is there any other way to check the current route?
P.s. thanks for a great plugin :+1:
Hello,
I ended up doing like this :
// in header.php :
if(get_query_var('is_route_wiki') == 'true') echo 'menu-active';
// in functions.php :
$route_args = array(
'path' => '^wiki',
'query_vars' => array(
'is_route_wiki' => 'true' // ***** this is the line ***
),
'page_callback' => 'empty_callback',
'page_arguments' => array(),
'access_callback' => true,
'title' => 'Wiki',
'template' => array(
'templates/_wiki.php',
TEMPLATEPATH . 'templates/_wiki.php'
)
);
$router->add_route( 'wiki', $route_args );
Aah brilliant - that works for me! And thanks for the quick reply
you're welcome !
@jbrinley : do you plan adding an is_route('my-route');
template tag ? Just to know if I still need to use my hack with get_query_var()
... ;)
Stick with your code for now. I plan to add template tags in the future, and is_current_route()
will be among them. But I can't give you a timeline. Pull requests are welcome. :)
Ok good ! I'll try to do it, I let you know if I reach something ;)
Hello,
Is there a way to test what route I'm showing,
example, in my header.php, I'd like to do :
thanks