web-profile

Path to files in WordPress

$plugin_path = basename( dirname( __FILE__ ) );

Adding javascript and css files:

<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

<?php
echo get_template_directory_uri();
// or
echo get_bloginfo('template_directory');
?>

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

<?php
echo get_stylesheet_directory_uri();
// or
echo get_bloginfo('stylesheet_directory');
?>

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

<?php
echo get_template_directory();
// or
echo TEMPLATEPATH;
?>

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

<?php
echo get_stylesheet_directory();
// or
echo STYLESHEETPATH;
?>

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

<?php
echo WP_PLUGIN_DIR;
?>

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

<?php
echo WP_PLUGIN_URL;
?>

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

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

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

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

WordPress activate and deactivate plugin:

<?php 
$path_to_plugin = plugin_basename( __FILE__ ); // returns 'plugin-name/plugin.php'
deactivate_plugins( $path_to_plugin );
activate_plugins( $path_to_plugin );
?>

Leave a Reply

Your email address will not be published.