How to create admin toggle for displaying WordPress slider component

I’m working on a WordPress theme and need to add a control in the admin area that lets me enable or disable a slider component on the frontend. Right now I have this code that displays the slider:

<?php include locate_template('components/gallery/main-slideshow.php'); ?>

I want to be able to check or uncheck a box in the WordPress admin dashboard to control whether this slider shows up on my site or not. What would be the simplest approach to set up this kind of admin toggle? I’m looking for something that doesn’t require too much complex coding but gives me that on/off functionality from the backend.

The WordPress customizer is your best bet here. Just register a new setting in functions.php using the customizer API, then add a checkbox control to store the toggle state. In your template, wrap the slider include with a conditional that checks the customizer setting value. It integrates perfectly with WordPress core and gives you real-time preview. The setting won’t disappear when you update your theme if you set it up right, and you can grab it anywhere using get_theme_mod. Way less coding than building custom admin pages, and users will have a much better experience.

Great ideas! What about using ACF (Advanced Custom Fields) for this? You can set up a simple true/false field and it handles the admin UI automatically. Quick question - do you need this toggle for specific pages or across the whole site? That’d definitely change which approach works best.

yo, another way is to just dive into the wp_options table. Like, add add_option(‘show_slider’, ‘1’) in your functions.php. Then, wrap that include with get_option(‘show_slider’). For toggling in admin, use Settings API or just toss a simple meta box on the dashboard, whatever feels right!