Question

I'm having a run at developing a theme options plugin and right now working on implementing a 'hero' header, checking first to see if my plugin is active using:

if( function_exists( 'my_header_function ) ): my_header_function();
else: 
/* carry on and output the default header... */
endif;

Now as my hero header depends on whether the image and logo have been uploaded I wonder if I can manually return a 'false' result from my hook in order to have the original conditional in my header carry on an output the normal header.

Any ideas? Many thanks.

Was it helpful?

Solution

Have your function return your HTML rather than echo it. Perform the logic in the function to see if the image/logo are present and only return the HTML if that's the case, otherwise returning null/false.

function my_header_function( $output = false ) {
     if ( /*image and logo have been uploaded */ ) {
          $output = /* HTML of your hero header */;
     }
     return $output;
}

Add a check to your hook function to see if your function returns content; if it does, echo it.

if ( function_exists( 'my_header_function' ) && ( $hero = my_header_function() ) ) {
     echo $hero;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top