WordPress.org

Ready to get started?Download WordPress

Forums

php include not working in Header.php (9 posts)

  1. jmwebguy
    Member
    Posted 3 years ago #

    Using WordPress MU.

    I am trying to reference a file located in an individual blog's blog.dir/files directory.

    in header.php for the THEME, I added:

    <?php include (get_bloginfo('url') . '/files/test.html'); ?>

    I know it's the right path and a direct link to it works. What am I doing wrong? I need to be able to include the TXT that's in that file.
    I'll have this file in multiple blogs.dir/files folders.

  2. Try this...

    <?php
    $url=get_bloginfo('url');
    include($url. '/files/test.html'); ?>

    I don't think include likes the variable in it for some reason.

  3. I'll have this file in multiple blogs.dir/files folders.

    Why not just put it in one spot? Or will they all be different?

  4. jmwebguy
    Member
    Posted 3 years ago #

    Ipstenu, I tried that before I posted. Just tried again and it didn't work. I can even do an echo write on that $url plus the file location and it points out the right location.

    Andrea, They will all be different. I am putting ad tags in them and figured this would be the easiest way. I will put one in the header and one in the footer.

    I can't figure out why this is so difficult. Even if I put the full url in the include, it doesn't work. It's like it's ignoring it, yet other includes (in the single.php) works.

  5. Even if I put the full url in the include, it doesn't work.

    ... Wait a second.

    What's the FULL URL you're trying to use? Is it like domain.com/subsite/files/test.html or domain.com/blogs.dir/2/files/test.html ?

  6. ricozor
    Member
    Posted 3 years ago #

    Hy,

    I have also the same problem,
    Like jmwebguy, I want to includes php files witch are located in the parent directory of the Blog

    I've tried <?php include (get_bloginfo('url') . '/myfile.php'); ?> first and <?php include ('../../../../../myfile.php'); ?> next

    the problem is the same.

    the only include, seams to work, is when header.php and the other file are in the same directory.

    Any idea ?

  7. ricozor
    Member
    Posted 3 years ago #

    I have found the solution right here :
    http://wordpress.org/support/topic/include-php-files-at-absolute-urls?replies=5

    you have to write your incude like this :
    <?php include(ABSPATH . "../myfile.php"); ?>

    ABSPATH is the root of your wordpress blog

  8. You can also use get_bloginfo( 'wpurl' ) :) You were VERY close with your 'url' call!

    <?php include( get_bloginfo( 'wpurl' ) . "/myfile.php"); ?>

  9. Curtiss Grymala
    Member
    Posted 3 years ago #

    include() with a URL will only work under certain specific circumstances on a server (and even then, IIRC, if you are including a PHP file, it will include the parsed version rather than the raw PHP code). include() and require() statements should always use paths (/var/www/...) rather than URLs if you want them to work consistently and properly.

    EDIT - You can read a little more about what I mentioned above by reading the second paragraph below Example #2 on the PHP doc page for the include() function.

Topic Closed

This topic has been closed to new replies.

About this Topic