get_template_directory() returns nothing

I’m doing some custom theme work for the first time and I want to use

<?php get_template_directory(); ?>/main.css 

to access the CSS file. However, when this renders in the html, it renders as:

Read More
/main.css

It’s possible I deleted whatever setting or option that WordPress uses to derive this path. What logic does WordPress use to determine what the template directory is?

As a test, I added this code:

DIRS:

Plugins
<?php plugins_url(); ?>
<?php plugin_dir_url(); ?>
<?php plugin_dir_path(); ?>
<?php plugin_basename(); ?>
Themes
<?php get_template_directory_uri(); ?>
<?php get_stylesheet_uri(); ?>
<?php get_theme_root_uri(); ?>
<?php get_theme_root(); ?>
<?php get_theme_roots(); ?>
Site Home
<?php home_url(); ?>
WordPress
<?php admin_url(); ?>
<?php site_url(); ?>
<?php content_url(); ?>
<?php includes_url(); ?>
<?php wp_upload_dir(); ?>
Multisite
<?php get_admin_url(); ?>
<?php get_home_url(); ?>
<?php get_site_url(); ?>
<?php network_admin_url(); ?>
<?php network_site_url(); ?>
<?php network_home_url(); ?>

and it rendered as:

DIRS:
Plugins
Themes
Site Home
WordPress
Multisite

So it’s pretty clear that I messed up something WordPress needs to determine it’s directories. But I can’t find anything in Google about how WordPress comes up with these paths and the source code isn’t obvious to me either.

Related posts

Leave a Reply

2 comments