I'm a Javascript developer and I am very new to PHP/Wordpress. So just like what I saw from samples around the internet I wrote my functions.php script to add my custom css file like this:
functions.php
<?php
echo '<h1>CASH ME OUTSIDE</h1>';
add_action('wp_enqueue_scripts', 'theme_styles');
function theme_styles()
{
echo '<h1>CASH ME INSIDE</h1>';
wp_enqueue_style('theme_styles', get_template_directory_uri() . '/foo.css');
}
?>
To check if the functions.php is being called I printed <h1>CASH ME OUTSIDE</h1> and it did appear. How ever the echo inside the function theme_styles() is not being printed which leads me to the conclusion that the function is not being called.
echoin functions.php,wp_enqueue_scriptsor any other non-template file probably breaks the output due to a fatal error because of headers already sent.echois not a proper way to debug. Delete the echo statements and check the HTML of the page, your css should be there. To debug, use error logs. Other than that, your code seems correct; be sure to includewp_head()andwp_footer()in your theme.