get_template_directory()不返回任何内容

时间:2013-03-12 15:56:43

标签: wordpress wordpress-theming

我第一次做一些自定义主题工作,我想使用

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

访问CSS文件。但是,当这在html中呈现时,它呈现为:

/main.css

我可以删除Wordpress用于派生此路径的任何设置或选项。 Wordpress使用什么逻辑来确定模板目录是什么?

作为测试,我添加了以下代码:

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(); ?>

并呈现为:

DIRS:
Plugins
Themes
Site Home
WordPress
Multisite

所以我很清楚我搞砸了Wordpress需要确定它的目录。但我在Google上找不到关于Wordpress如何提出这些路径的任何内容,而且源代码对我来说也不明显。

2 个答案:

答案 0 :(得分:3)

get_template_directory 返回字符串。 It doesn't echo that string。对于以get_开头的WordPress函数,这是非常常见的行为。尝试:

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

答案 1 :(得分:0)

根据您的计划,您还可以使用:

<?php bloginfo('template_url'); ?>
相关问题