skip to Main Content

There is a template part called ‘theme-section-1.php’, and a css file called ‘theme-section-1.css’.
I want to load the css file only if ‘theme-section-1.php’ is called. an if/else statement loads the template which is controlled by a checkbox in the dashboard.

2

Answers


  1. You can simply do this by :

    $checkbox = true; // Fetch the value of checkbox from database.
    
    if ( $checkbox ) {
       wp_enqueue_style( 'style-name', get_stylesheet_uri() );
    }
    

    References:

    Login or Signup to reply.
  2. is_page_template() does exactly that

    if (is_page_template('path/to/template.php')) {
        // enqueue style
    }
    

    The path/to/template starts from your theme directory

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search