Forums

How to dynamically get theme directory? (9 posts)

  1. anothertrad
    Member
    Posted 2 years ago #

    Hi. My question is simple: how to get the theme directory.
    I was developing an website in wordpress, that in my localhost it was:
    localhost/sites/project_name/

    so, in my header.php I put the css path:
    <link src="/sites/project_name/wp-content/themes/my_theme/css.css"

    but, when I send it to other developer, his address structure was:
    localhost/projects/blalba/project_name/

    then wordpress couldn't find the css.

    so, how to dynamically get my current template`s root directory path?

    thanks.

  2. kurosquare
    Member
    Posted 2 years ago #

    Try this.
    <?php bloginfo('template_directory');?>/css.css

  3. anothertrad
    Member
    Posted 2 years ago #

    Thanks. it works.
    But please, show me the link of the documentation of his useful bloginfo functions.
    Thanks again.

  4. kz
    Member
    Posted 2 years ago #

  5. anothertrad
    Member
    Posted 2 years ago #

    There`s a way to get the plugin directory?

  6. kurosquare
    Member
    Posted 2 years ago #

    if(function_exists('plugins_url')){
    	$plugin_url = plugins_url($plugin_dir . '/');
    }else{
    	$plugin_url = get_bloginfo('wpurl') . '/'
    	. (defined('PLUGINDIR') ? PLUGINDIR . '/': 'wp-content/plugins/')
    	. $plugin_dir . '/';
    }
  7. anothertrad
    Member
    Posted 2 years ago #

    got it

  8. anothertrad
    Member
    Posted 2 years ago #

    Let me tell you something about this function bloginfo('template_directory').
    For me, it returns: "localhost:8888/sites/project_name/wp-content/themes/my_theme/"
    Everything ok.
    When I open my wordpress project trought another computer in the network, I put my_ip:8888, like:
    192.168.0.4:8888/sites/project_name

    when I go to the code, I expect that the function bloginfo('template_directory') returns to me:
    "192.168.0.4:8888/sites/project_name/wp-content/themes/my_theme/"

    Instead, it returns:
    "localhost:8888/sites/project_name/wp-content/themes/my_theme/"

    Maybe it`s a site-name configuration in apache?

    well, maybe if I remove the characters before the first slash, it may be work...

  9. anothertrad
    Member
    Posted 2 years ago #

    I wrote a little function to remove "localhost:8888" from the address, leaving the relative directory.

    But the function wp_head() stills put localhost:8888 in front of the css links, and I`m afraid that I can't change this, right?

Topic Closed

This topic has been closed to new replies.

About this Topic