My Example:
function example() {
if ($checked) echo 'true';
}
add_action('wp_head', 'example');
now, if not $checked
, will wordpress do an empty add_action
or will avoid it?
if do, how I can just add action if $checked
is true?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityThe function will run, but nothing will happen. There is a small overhead, but you shouldn't worry about it, the possible savings are minimal.
Depending on when you have $checked available, you could also do
function example() {
echo 'true';
}
if ($checked) add_action('wp_head', 'example');
$checked
2 times? one inside function and second outside it?