WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Can Header.php be used elsewhere on a site? (12 posts)

  1. mapBaker
    Member
    Posted 1 year ago #

    All,

    Can the header.php file be used on a different website on the same server?

    For example, can the header from http://www.blog.com/content be used on the main page of http://www.blog.com/ - which is a custom page?

    Would PHP allow you to just point to the file?

    Thanks!

    -mb

  2. Andrew Bartel
    Member
    Posted 1 year ago #

    This is what you're looking for: get_template_part().

  3. mapBaker
    Member
    Posted 1 year ago #

    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

  4. CodeBotics
    Member
    Posted 1 year ago #

    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')
    ?>
  5. mapBaker
    Member
    Posted 1 year ago #

    Unless I'm doing something wrong, that doesn't seem to work...

    Have you been successful with this before?

    -mb

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    Is your custom file a php file? or html?

  7. CodeBotics
    Member
    Posted 1 year ago #

    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 http://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

  8. mapBaker
    Member
    Posted 1 year ago #

    @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

  9. mapBaker
    Member
    Posted 1 year ago #

    @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>

  10. CodeBotics
    Member
    Posted 1 year ago #

    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

  11. mapBaker
    Member
    Posted 1 year ago #

    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

  12. mapBaker
    Member
    Posted 1 year ago #

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

    Thank you anyway!!!

    -m

Topic Closed

This topic has been closed to new replies.

About this Topic