You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that I could use do_action('my_custom_action') / did_action('my_custom_action') check as follows:
add_action('cortex.routes', function (RouteCollectionInterface$routes) {
$routes->addRoute(newQueryRoute(
'/my/route',
function (array$matches) {
do_action('my_custom_action');
return [
// params
];
}
));
});
add_filter('body_class', function ($classes) {
if (!did_action('my_custom_action')) {
return$classes;
}
returnarray_merge($classes, ['my_class']);
});
or I could add some custom query variable and then add custom classes depending on the query variable existence... but none of these methods sound right to me.
Is there a more elegant way?
The text was updated successfully, but these errors were encountered:
@gmazzap
Thank you very much for a very comprehensive response. The second solution is exactly what I was looking for - much cleaner than a solution based on did_action that I came up with :)
I know that I could use
do_action('my_custom_action')
/did_action('my_custom_action')
check as follows:or I could add some custom query variable and then add custom classes depending on the query variable existence... but none of these methods sound right to me.
Is there a more elegant way?
The text was updated successfully, but these errors were encountered: