• Hello forums.

    I’m editing my sidebar.php template. I want to add an image at the top so I did it like so:

    <? $p = get_theme_root();
    	 echo  '<img src="'.$p.'/default/images/spiel.jpg"  alt="Recent Posts"/>';
    	 ?>

    However it outputs something like this:

    <img src="C:\xampplite\htdocs/wp-content/themes/default/images/spiel.jpg" alt="Recent Posts"/>

    Question: is there a function built in in wordpress to output the path to the themes so I won’t have to hardcode the entire URL everytime I need to insert images. Besides I’m still developing it on my localhost and it will be nice to just upload it on a live server without editing the paths latter.

    I’m planning to set my own path using GET[‘servername’] but I want to know if wordpress has a built in function before doing so.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter stonedeft

    (@stonedeft)

    This seems ok but I need a better solution in case I plan to change themes later:

    echo'<img src="http://'.$_SERVER['HTTP_HOST'].'/wp-content/themes/default/images/spiel.jpg" alt="Recent Posts"/>';

    Question: is there a function built in in wordpress to output the path to the themes…

    Yes, bloginfo is used for this:

    http://codex.wordpress.org/Template_Tags/bloginfo

    Also, if you are editing the default theme, you need to make a copy of it and then give the copy a new directory name and theme name in style.css so that a future auto update won’t overwrite it.

    Thread Starter stonedeft

    (@stonedeft)

    Thanks for the reply however:

    <h1><?php bloginfo('name'); ?></h1>

    Will display the blog name

    <p>Character set: <?php bloginfo('charset'); ?> </p>

    Will Display the Charset and

    <p><?php bloginfo('description'); ?> </p>

    Will display the description… uhmm which one will display the path? please help.

    Also I see auto update will overwrite my edits OMG how can I disable auto updates?

    Thanks

    which one will display the path?

    template_directory or template_url

    Also I see auto update will overwrite my edits OMG how can I disable auto updates?

    Just rename the default theme and it’s folder and it won’t be a problem.

    Thread Starter stonedeft

    (@stonedeft)

    Thanks iridiax I did it like this:

    `echo’ <img src=”‘;
    bloginfo(‘template_directory’);
    echo ‘/images/spiel.jpg” />’;`

    Though wishing the bloginfo() function will return the values and not echo it so I can just do it like this:

    echo '<img src="'.bloginfo('template_directory').'/images/speil.jpg" />';

    Maybe I can make another function from the bloginfo() function that will return the value and not echo it. Another Question: which file in wordpress is the bloginfo() function located?

    I am currently using this:

    function getThemeURL(){
        $p = 'http://'.$_SERVER['HTTP_HOST'].'/wp-content/themes';
        return $p;
    }

    Thanks. Please bear with me this is my first WP site still figuring out hooks and stuff…

    bloginfo is somewhere in the WordPress core and it is already echoed so you don’t echo it. See:

    http://codex.wordpress.org/Theme_Development#Referencing_Files_From_a_Template

    If you are looking for a different tag/function, check here:

    http://codex.wordpress.org/Template_Tags
    http://codex.wordpress.org/Function_Reference

    Thread Starter stonedeft

    (@stonedeft)

    I’ll check out those links many thanks

    You look great !

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Path to themes.’ is closed to new replies.