Viewing 11 replies - 1 through 11 (of 11 total)
  • This is what you’re looking for: get_template_part().

    Thread Starter mapBaker

    (@mapbaker)

    Andrew,

    Interesting!

    For some reason I can’t get this, or get_header

    Any further examples would be great.

    Also: is there a way to simply include the files using a standard php include?

    And: does get_template and/or get_header work outside the WP install directory?

    Thank you!!!

    -mb

    I think for what you’re trying to do, you’ll need include(‘path/to/header.php’).

    Fore example:

    <?php
    include('/content/wp-content/themes/themename/header.php')
    ?>

    Thread Starter mapBaker

    (@mapbaker)

    Unless I’m doing something wrong, that doesn’t seem to work…

    Have you been successful with this before?

    -mb

    Is your custom file a php file? or html?

    This works for getting header.php from another theme on the same site:

    <?php $currentdir = dirname(__FILE__);
    include($currentdir.'/../themename/header.php'); ?>

    To get it from a different site, assuming the files for the site at URL https://www.blog.com/content are in a directory called content you’d need to use something like:

    <?php $currentdir = getcwd();
    include($currentdir.'/content/wp-content/themes/themename/header.php'); ?>

    I haven’t tested the second one, but the first one definitely works!

    CB

    Thread Starter mapBaker

    (@mapbaker)

    @codebotics:

    I tried a page.php (at the server root) with this code:

    <html>
    <body>
    <?php $currentdir = dirname(content/wp-content/themes);
    include ($currentdir . ‘/../twentytwelve/header.php’);
    ?>
    </body>
    </html>

    …to no avail. What do you suggest?

    Thank you for this! I think we’ll get this to work…

    -m

    Thread Starter mapBaker

    (@mapbaker)

    @rev Voodoo:

    these are .php pages with HTML and PHP script within.

    example from where I’m at now:

    (filename: page.php)

    <html>
    <body>

    <?php $currentdir = dirname(content/wp-content/themes);
    include ($currentdir . ‘/../twentytwelve/header.php’);
    ?>
    </body>
    </html>

    This code:
    $currentdir = dirname('content/wp-content/themes');
    will just return ‘content/wp-content’ as far as I know. Note the single quotation marks I’ve added.

    Could you explain your folder structure to me? The way I understand it is this:
    root directory -> content -> wp-content -> themes -> twentytwelve

    In which case, did you try using the code I posted earlier without changing anything?

    <?php $currentdir = getcwd();
    include($currentdir.'/content/wp-content/themes/themename/header.php'); ?>

    CB

    Thread Starter mapBaker

    (@mapbaker)

    CB,

    you’ve got the directory structure right on.

    i’ve put the code you cited into a .php fle with <html> and <body> tags.

    i get a blank screen in return.

    does the .php file need to have anything else in it?

    thanks again for your help,

    -m

    Thread Starter mapBaker

    (@mapbaker)

    All – Giving up on this. Even template authors have told me its not possible.

    Thank you anyway!!!

    -m

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Can Header.php be used elsewhere on a site?’ is closed to new replies.