loading css file via functions.php

I have been trying to work out why I can't get my css page to load using the wp_enqueue_scripts method within functions.php in my theme folder.

Here is the most simplified code currently that I am still having issues with, hopefully someone will notice something, if not at least assist me on where to diagnose next as I don't see anything with php and wordpress errors turned on.

function my_assets() {
	wp_enqueue_style( 'main-style', get_bloginfo('template_directory') . '/css/style.css',  '1.0', 'screen' );
	}

add_action( 'wp_enqueue_scripts', 'my_assets' );
echo get_bloginfo('template_directory') . "/css/style.css";

I can see that the path to the css file is correct and it's also accessible. I know that my css file works as I can load it via expressing the path in the header, it's just I am trying to follow the best method and I have many additional css and js files to eventually load too and believe this is the method needed.

Currently I've just spun up a fresh vps with basic out the box WordPress installed and my theme moved to here, again with debug enabled I don't see any errors at all, yet the page is lacking the styling which does work if loaded a different way.

What can I possibly do now as I am at a loss after spending a full day reworking this over and over with no success and no obvious errors.

  • Vinod Dalvi
    • WP Unicorn

    Hi Richard,

    Welcome to the WPMU Dev community and thank you for your question.

    If you want to load the style.css fiile on the page stored in the root directory of the theme then please use the following code.

    function my_assets() {
    	   wp_enqueue_style( 'main-style', get_stylesheet_uri(), false );
    	}
    
    add_action( 'wp_enqueue_scripts', 'my_assets' );

    If you want to load the style.css fiile on the page stored in the css directory of the theme then please use the following code.

    function my_assets() {
    	wp_enqueue_style( 'main-style', get_stylesheet_directory_uri. '/css/style.css',  '1.0', 'screen' );
    	}
    
    add_action( 'wp_enqueue_scripts', 'my_assets' );

    If nothing above helps you then please share me the page URL from your site where it's not working so that i can troubleshoot it.

    Best Regards,
    Vinod Dalvi

  • Richard
    • WPMU DEV Initiate

    Hi Vinod,

    Thanks for the response, yes it's not the default style.css just has the same name, however it's full of the sites main styling and is within theme/css/ folder.

    I attempted the code you suggested and not been successful unfortunately.

    Currently the site is at latest.smallbyte.co.uk It was a static page before that I am now 'trying' to bring in to WordPress.

    Thank you for your assistance.

  • Vinod Dalvi
    • WP Unicorn

    Hi Richard,

    I could confirm it's not loading on your site.

    Where are you adding the provided code?

    Would you mind if I logged in to your site and did some troubleshooting? This might help get to the bottom of this faster. If this is ok, just grant me temporary admin access to your site by clicking "Grant Access" button in the WPMU DEV Dashboard Settings as described on the following page and reply on this thread after granting it?

    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Regards,
    Vinod Dalvi

  • Richard
    • WPMU DEV Initiate

    Hi Vinod,

    I've installed the WPMU Plugin and granted access, this server is a dummy just for testing clean install and plugins from interfering, please feel free to do anything you like to this server. Thanks for taking a look.

    Kind regards,

    Richard.

  • Vinod Dalvi
    • WP Unicorn

    Hi Richard,,

    Thank you for granting the support staff access.

    I tried to access your site using support staff access but got a lot of warning messages as shown in the attached screenshot which is generated by theme lartigiano-wp that you are using therefore i couldn't access it.

    Do you have WP_DEBUG set to true in your wp-config.php file?

    If you do then please set it to false.

    If it's already false then could you please just send log in info through our secured contact form: https://premium.wpmudev.org/contact/
    - Choose "I have a different question"
    - Include my name in the subject "Vinod Dalvi"
    - Include the URL of this post in your message so that I may track this issue better
    - Include login information (Wordpress admin info username + password )
    - Include FTP Details

    Regards,
    Vinod Dalvi

  • Richard
    • WPMU DEV Initiate

    I just wanted to update this thread saying that I didn't get the wp_enqueue_script method to work, but I've since gone with using direct tags in the header and this is currently working for my purposes and I don't have the time to further test the particulars of this issue now.

    Thank you Vinod for trying to assist me with the issue I was having.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.