• On my wordpress site I have a seperate php newsletter script. Is there a way to include the header & footer from my wordpress site on my newsletter page script?

    Thanks,
    Brandon

Viewing 11 replies - 1 through 11 (of 11 total)
  • Yes – just use a <?php include(‘path/to/header.php’): ?> and the same for footer where you want them to appear.
    That help ?

    On a default WordPress install, your theme files are located in wp-content/themes/. Let’s say, for example, that you have this directory structure:

    /
    /blog/ <– WordPress install
    /newsletter/ <– newsletter

    in your newsletter file, add

    <?php include('../blog/wp-content/themes/theme-name/header.php'); ?>

    where theme-name is the folder in which you have your theme. Same goes for footer.php.

    I know this is just a verbose way of trying to say what podz did, but hey, it may help.

    There is a bit of an issue with doing this, though. You’re going to run into crap that uses the WordPress template tags since they’ll no longer be included by default. It may be worthwhile to re-create the header without those template tags in them for the newsletter object. Yeah, it’s not dynamic, but it could be less of a pain if it’s only a small thing.

    WPChina

    (@wordpresschina)

    Right, this is something I too have been struggling with my blog.

    A few weeks ago I relented and just copied the header.php and footer.php into other files and include those for my non-WP pages. The header.php and footer.php do contain WP tags, and because they were causing problems on the non-WP pages, I had to remove them from BOTH the WP and non-WP header/footer files so that I could have uniformity across my site.

    Bottom line: in the future it would cool to see some way to still have WP tags working within the template tags regardless of whether WP or non-WP pages are including those.

    Or…. if there is some certain code to add within each non-WP page so that the WP tags are usable within the tags on non-WP pages, that would be fantastic! ??

    <?php include (‘path/to/wp-blog-header.php’): ?>

    Use that on any .php page you have and you can use any WP function / plugin.

    Put it inside the <head> tags.

    WPChina

    (@wordpresschina)

    really podz? Let me check… I think in the past I was not including <head> in the php page because the header already contained this, but I will try your suggestion…

    WPChina

    (@wordpresschina)

    Hmmmm….. I did this:

    <html><head>
    <?php include (‘var/www/html/wp-content/themes/theme1/header.php’); ?>
    </head><body>
    content
    </body></html>

    the “content” showed up, but the header did not show. this was all stripped out of the page:

    <?php include (‘var/www/html/wp-content/themes/theme1/header.php’); ?>

    It was as if I never had placed that include in the first place…. any idea what is going on?

    Sorry – my mistake!
    In any other .php page, this must go inside the header:

    <?php include ('full/url/to/wp-blog-header.php'): ?>

    then you can include the header:

    <?php include ('https://www.example.com/wp-content/themes/theme1/header.php'); ?>

    Try that ?

    WPChina

    (@wordpresschina)

    Ok, I tried this:

    <html><head>
    <?php include (‘https://www.example.com/wp-content/themes/theme1/header.php&#8217;); ?>
    </head>
    <body>
    content
    </body>
    </html>

    Now it works better, but not quite. Now it seems to be trying to include the header.php, but at the first instance of a WP variable, it stops and skips down to the rest of my page. Therefore, when I view source, I see this:

    <html><head>
    <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “https://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”&gt;
    <html xmlns=”https://www.w3.org/1999/xhtml”&gt;
    <head profile=”https://gmpg.org/xfn/11″&gt;
    <title>
    </head>
    content
    etc…

    You see the <title>? After that is just stops… so it seems it can’t do anything with the WP tags. Hmmmm….

    WPChina

    (@wordpresschina)

    Wait, sorry, I misread you instructions. I am now doing this, but it is still not working (i.e. It seems to jump at the title tag and skips all the header stuff and goes straight to the content):

    <html><head>
    <?php include (‘https://www.example.com/wp-blog-header.php&#8217;); ?>
    <?php include (‘https://www.example.com/wp-content/themes/theme1/header.php&#8217;); ?>
    </head>
    <body>
    content
    </body>

    WPChina

    (@wordpresschina)

    When you say “In any other .php page, this must go inside the header”, you mean in my non-WP php pages, right? Or do you mean something else?

    And does this also goes in the <head> of the non_WP php pages:

    <?php include (‘full/url/to/wp-blog-header.php’): ?>

    tks!

    Hi i have tried this but nothing seems to work out!
    i have folder in ../blogs/test/header.php

    In header.php i have code:

    <html><head>
    <?php include (‘https://www.example.net/wp-content/themes/k2/header.php&#8217;); ?>
    </head>
    <body>
    content
    </body>
    </html>

    when i visit : https://blogs.example.net/test/header.php
    it returns:

    arning: main(https://www.example.net/wp-content/themes/k2/header.php) [function.main]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/example/public_html/blogs/test/header.php on line 2

    Warning: main() [function.include]: Failed opening ‘https://www.example.net/wp-content/themes/k2/header.php&#8217; for inclusion include_path=’.:/usr/lib/php:/usr/local/lib/php/extensions:/usr/local/lib/php’) in /home/example/public_html/blogs/test/header.php on line 2

    any idea what to do?
    content

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How can header footer be used on a non WordPress page?’ is closed to new replies.