Assigning a Setting to a Variable and Using it in an if Statement

UPDATE: Per your comment, DDS means Disable Dynamic Style and is true when enabled, so I have modified the function accordingly. check for -> if ( is_category() && ! $DDS ) :


Short answer, yes you can use a variable representing this function get_theme_mod('dds')

Now I don’t know what will be the result of that function, so consider checking what is considered false when converting to a bool. To sum it up, empty strings, arrays objects and 0 are considered false, every non zero number (positive or negative) and non empty strings, arrays, objects will be considered true.

so you can have

$DDS = ! empty( get_theme_mod('dds') ) ? get_theme_mod('dds') : false ;

which uses the ternary operators to set the variable and then your if statement

if ( is_category() && ! $DDS ) :
  // Print CSS Style
endif;

NOTE

using the syntax if endif; is best when you have long functions, because you can visually see when the if ends, so it improves readability. Also when using a lot of HTML within your PHP, it provides the same benefits of readability. But in the end, it’s a question of preferences.

EDIT

I just noticed another fault with your logic when assigning your $DDS variable. You are essentially storing into that variable, the results of a check. You are saying get_theme_mod('dds') is not false, so it’s true, and it will always be!

if you want to work with the actual value of that function, you need to use the ternary operator as I have provided.