Three Ways to Quickly Get the WordPress Current Theme Folder Directory

Publish: 2015-11-07 | Modify: 2018-08-04

When creating a WordPress theme, you may need to reference files in the current theme folder, such as the favicon.ico icon and js/jQuery. Therefore, you need to quickly obtain the path of the current theme directory.

Firstly, let's see how to call the website domain address:

<?php bloginfo('url');?>

Getting the theme directory is also very simple, with three methods as follows:

// Method 1
<?php bloginfo('template_url');?>

// Method 2
<?php bloginfo('template_directory'); ?>

// Method 3
<?php echo get_template_directory_uri(); ?>

For example, if you want to call the jquery.js library in the js folder of the theme folder, you can use any of the methods:

<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery.js"></script>

Furthermore, if you want to call the style.css stylesheet in the theme folder, there is an even faster method:

<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" />

Original article from: Three ways to quickly get the WordPress current theme folder directory, all rights reserved to the original author. If there is any infringement, please contact QQ: 337003006 for deletion.


Comments