How can the use of echo and return statements affect the output of custom PHP functions in Wordpress themes?

Using both echo and return statements in a custom PHP function can cause unexpected behavior in Wordpress themes. Echo statements directly output content to the browser, while return statements pass a value back to the caller. To avoid conflicts, it's best to choose one method to use consistently within the function. If you need to return a value and also display content, you can store the content in a variable and then return it at the end of the function.

function custom_function() {
    $output = 'Content to be displayed';
    
    // Use echo to display content
    echo $output;
    
    // Use return to pass a value back
    return $output;
}