Exclude some categories from the post page

Yes your code will fail, but not because the above answer, but because this isn’t the page you ask for.

As you wrote, you set the page “videos” to be the page where all the posts are shown.

When a page is set as a blogpage, WordPress will use home.php or index.php according to the template hierarchy to display the blogpage, not a page template. This page is regarded as the home page, so is_home() will return true on this page

So, to exclude the categories, you need to use this conditional:

function exclude_category($query) {
    if(is_home()){
       $query->set('cat', '-42, -43');
    }
    return $query;
}
    add_filter('pre_get_posts', 'exclude_category');

Happy Coding,

Kuchenundkakao