Path to files in WordPress

1
$plugin_path = basename( dirname( __FILE__ ) );

Adding javascript and css files:

1
2
3
<link href="<?php bloginfo('stylesheet_directory'); ?>/css/style.css" rel="stylesheet" />
 
<script src="<?php bloginfo('stylesheet_directory'); ?>/js/script.js"></script>

Other functions for getting path to files in WordPress or bloginfo variables or bloginfo.

If we don't have parent-child theme scheme than all constants based on parent-child scheme will return the same values.

Parent theme path: http://site.com/wp-content/themes/parent

1
2
3
4
5
6
7
8
9
<?php
 
echo get_template_directory_uri();
 
// or
 
echo get_bloginfo('template_directory');
 
?>

Child theme path: http://site.com/wp-content/themes/child

1
2
3
4
5
6
7
8
9
<?php
 
echo get_stylesheet_directory_uri();
 
// or
 
echo get_bloginfo('stylesheet_directory');
 
?>

Absolute parent theme path: D:/site/wp-content/themes/parent

1
2
3
4
5
6
7
8
9
<?php
 
echo get_template_directory();
 
// or
 
echo TEMPLATEPATH;
 
?>

Absolute child theme path: D:/site/wp-content/themes/child

1
2
3
4
5
6
7
8
9
<?php
 
echo get_stylesheet_directory();
 
// or
 
echo STYLESHEETPATH;
 
?>

Path to plugins dir: D:/site/wp-content/plugins

1
2
3
4
5
<?php
 
echo WP_PLUGIN_DIR;
 
?>

Absolute path to plugins dir: http://site.com/wp-content/plugins

1
2
3
4
5
<?php
 
echo WP_PLUGIN_URL;
 
?>

Admin link: http://site.com/wp-admin/plugin.php

1
<?php admin_url('plugins.php'); ?>

Absolute link to plugin folder: D:\htdocs\site\wp-content\plugins\plugin-name/

1
<?php $plugin_folder_url = plugin_dir_path( __FILE__ ); ?>

WordPress activate and deactivate plugin:

1
2
3
4
5
6
7
8
9
<?php
 
$path_to_plugin = plugin_basename( __FILE__ ); // returns 'plugin-name/plugin.php'
 
deactivate_plugins( $path_to_plugin );
 
activate_plugins( $path_to_plugin );
 
?>

Leave a Comment