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”
Thanks Marouane! That worked, with one minor addition; there was a missing end bracket for } for the first slider in line 8. When I tested it, it does display the slider, but not a full width slider. Normally I’d set this on the page/post under Slider Options, but there is no 404 page to edit in admin. I’m sure it can be set somehow with the “tc_slider_layout” hook, but I tried a couple of ways and failed. Do you know what the appropriate code would be?
Thanks again for your help.
I don’t want to waste your time because I coudln’t test it but, if you want may be you can try this:
Any chance you could update this article (i.e. provide the new snippet) for post 3.1 installations? I’m afraid custom hooks are a bit over my head. Is it possible to setup a different sliders: one for the 404 and another for the search? Thanks.
Hi redpete,
Yes you can select one of the conditions used in the example to achive this. is_404() for example.
If you are not familiar with Php and / or WordPress coding, you’ll want to start by the basics.
Hope this helps: !
I’m not an advanced user and I hope experts would correct me if I’m wrong. But something like this should work:
Thank you very much! But is there any way to put a personlized picture instead of the slider please in the 404 and search pages?
Thank you!
Hi Marouane,
Take a look at the 404 page code, there are plenty of hooks where you can add your callbacks.
More about the hooks API.
Hope this helps!