Three Methods to Quickly Get the Current WordPress Theme Directory Path
When developing a WordPress theme, you often need to reference files within the current theme folder in header.php and footer.php, such as the favicon.ico icon or JavaScript libraries like jQuery. Therefore, it is essential to know how to quickly retrieve the path to the current theme directory.
First, let's look at how to call the website's domain address:
<?php bloginfo('url'); ?>
Getting the theme directory is equally simple. Here are three methods:
// 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 located in the js folder within the theme directory, you can use any of the methods above. Here is one example:
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery.js"></script>
Additionally, if you want to call the theme's CSS stylesheet (style.css), there is an even faster method:
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" />
Original source: Three Methods to Quickly Get the Current WordPress Theme Directory Path. All rights reserved by the original author. If there is any infringement, please contact QQ: 337003006 for deletion.