Nesting Functions within Functions

It might look more elegant, but you don’t want to nest hooks in this way. You’re now ending up with actions added inside a logic check inside another action hook.

Instead, keep your functions as granular and atomic as possible and only hook them in where needed. Your first technique isn’t inefficient at all, it’s the way you should be doing things.

One major consequence of changing things up is the order of operations.

In your first example:

When firing the themeatic_sidebar hook, call the home_function_b() function. Inside the function, check to make sure you’re on the front page before doing something.

In your second example

When firing the thematic_above_header hook, check to see if you’re on the front page. Then, wait for the thematic_sidebar hook. Then call the home_function_b() function.

The logic between each example is very different. Let’s say home_function_b() needed to do one thing if is_front_page() is true and something else if it’s false … you second example wouldn’t allow that at all.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)