Display a slider in the 404 and search pages

⚠️ Code snippets might not be compatible with the latest version of your theme. Always use a child theme to customize your theme, and test your code on a staging website before migrating to production.

Let’s say you have created a slider named “my-slider” and you want to display it in your 404 page or in your search pages. Since there’s no option to style those pages from the WP admin, you’ll have to code something.

Here’s a short snippet to do it.

add_filter('tc_show_slider' , '__return_true' );
add_filter('tc_slider_active_status' , '__return_true' );
add_filter('tc_slider_name_id' , 'set_slider_name');
function set_slider_name( $original_name ) {
  if ( ! is_404() && ! is_search() )
    return $original_name;
  return 'my-slider';//<= write the name of your slider here
}
add_filter( 'tc_customizr_script_params', 'tc_allow_slider_autoplay');
function tc_allow_slider_autoplay( $_params ) {
  $_params['SliderName'] = ( is_404() || is_search() ) ? 'true' : $_params['SliderName'];
  return $_params;  
}

Paste this code in the functions.php file of your Customizr theme or child theme.

7 thoughts on “Display a slider in the 404 and search pages”

Comments are closed.