• Resolved soarwithcondor

    (@soarwithcondor)


    I’m using the WordPress constant TEMPLATEPATH to create variables within my functions.php that I use to link to specific images/scripts/etc within my theme’s directory (to help keep it organized). For example:

    define('CONDOR_LIB',TEMPLATEPATH . '/lib');
    define('CONDOR_ADMIN', CONDOR_LIB . '/admin');
    //... other code I'm removing to keep this simple
    define('CONDOR_ADMIN_IMG', CONDOR_ADMIN . '/img' );

    Then these variables would be used like this:

    // I include my php file within functions.php like this:
    require_once(CONDOR_ADMIN . '/admin-aesthetics.php');
    // this is an example of its use in admin-aesthetics.php
    body { background: #000 url(' . CONDOR_ADMIN_IMG . '/login-bg.jpg) top center repeat-x !important; margin: 0; height: 100%;}

    Now, that is working *perfectly* fine. Because it will output something like this:
    body { background: #000 url(/Applications/MAMP/htdocs/wp-content/themes/lotusDestiny/lib/admin/img/login-bg.jpg) top center repeat-x !important; margin: 0; height: 100%;}
    However, that image NEVER shows up though when I’m viewing the website on my localhost. And the image IS there because if I copy>paste that exact path into my browser window, it shows the image as being there.

    The images aren’t showing up in both Safari and Firefox. It seems like there’s some kind of security issues with loading images from outside the https://localhost environment or something…. I’m just not sure if there’s a way to force TEMPLATEPATH to read from https://localhost instead? Is there a different constant I should be using instead?

    I tried searching but the wordpress forums were returning nothing but a blank page and I can’t seem to find any answers through Google to fixing this.

    I assume it would work just fine in a live environment, but I don’t want to have to work completely on my live servers when I can build/test so much quicker locally… and of course TEMPLATEPATH makes it infinitely easier to re-use and deploy for future projects…

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter soarwithcondor

    (@soarwithcondor)

    Of course, I figured out the solution half an hour after I finally post out of 2 days of frustration. Sigh.

    When loading images and javascript, it appears that you need to use: get_template_directory_uri() instead of TEMPLATEPATH. In other words, my custom defined constant above should look like this:
    define('CONDOR_ADMIN_IMG', get_template_directory_uri() . '/lib/admin/img' );

    Also, since I found out about this function just now, I’ll add some extra info for the archives…

    If you’re using child themes with the above function, you should consider changing it to: get_stylesheet_directory_uri() (otherwise the call above will reference the parent theme, not the child).

    Sigh… this always happens to me, haha. Anyway, glad I fixed it and hope this helps someone else in the future ??

    Thank you for posting this! Saved me a huge headache!

    I was running into the same rub creating a custom widget to integrate into a theme. Defining the widget within functions.php and trying to point to an image file within the widget. The path was correct, however the image was not rendered properly.

    I’m still a relative newb to php, and everything seemed normal in the coding, but the server path to an image wasn’t doing what I wanted. Typing in the absolute uri would work, but of course that wouldn’t be stable across different installations of the theme.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘localhost TEMPLATEPATH mamp = images not working?’ is closed to new replies.