I have this apply filter in my plugin.

$pre_html = apply_filters( 'events_views_html', null, $view_slug, $query, $context );

I want to change $view_slug value dynamically from child theme using add_filter because I do not want to modify plugin files. But this code is not working. It is displaying value of $view_slug instead of displaying complete page content.

function add_extra_val( $view_slug, $query, $context  ){
    if (is_singular('tribe_events')) {
        $view_slug = 'single-event';
    return $view_slug;

add_filter('events_views_html', 'add_extra_val', 10, 3);

It is a basic question but I have limited knowledge of WordPress filters and hooks. Some guidelines regarding this will be appreciated.

2 Answers 2


Filters only allow you to directly modify the first value passed to them. In your case, that's null. If you shifted view_slug up a place, it would be available to filters using your events_view_html tag.

add_filter( 'events_view_html', 'my_callback', 10, 3); // passing 3 args to the callback, assuming you need them for something.

function my_callback( $view_slug, $query, $context ) {
// Do whatever you need to do to $view_slug
// $query and $context can be read but not changed
return $view_slug;
  • I tried this already but the page content is not displaying. Page only displaying the updated value of variable $view_slug.
    – wplearner
    Oct 27, 2020 at 18:16
  • I think you need to show more of your code.
    – vancoder
    Oct 27, 2020 at 21:17
  • I added my add_filter code above in my question.
    – wplearner
    Oct 28, 2020 at 12:22
  • Still no way of knowing what your plugin does with view-slug. that's probably where your problem lies. the filter itself looks fine.
    – vancoder
    Oct 28, 2020 at 18:28
Below is an example to modified the value using the add_filter hook:

// Accepting two arguments (three possible).
function example_callback( $view_slug, $query ) {
    return $maybe_modified_value;
add_filter( 'events_views_html', 'example_callback', 10, 2 ); // Where $priority is 10, $accepted_args is 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.