WordPress.org

Forums

[resolved] How To Call To A Diffrent Header Depending On The URL (2 posts)

  1. Jessica
    Member
    Posted 1 year ago #

    I would like to call to a different header depending on the url. I have tried this code:

    $url = $_SERVER["REQUEST_URI"];
    if (strpos($url, "/occupational/wohl/") === 0) {
     include "/wp-content/themes/wslh/header-wohl.php";
    } else {
     include "/wp-content/themes/wslh/header.php";
    }

    This does not appear to work. I placed it in the page.php and the index.php but for some reason I can not get it to function.

    Any thoughts on how this might work?
    Thank you in advance.

  2. Jessica
    Member
    Posted 1 year ago #

    Well, I was able to figure out how to do this, and as no one has replied, I figured I would place the answer in case it will help someone in the future.

    I placed the following code in my page.php:

    // Call to appropriate header
    $url = $_SERVER["REQUEST_URI"];
    if (strpos($url, "/url-here/page-name-here/") === 0) {
     get_header(newname);
    } else {
     get_header();
    }

    Note: if you have a header.php and then a header-newname.php, you can call to it like this:

    get_header(wohl);

Topic Closed

This topic has been closed to new replies.

About this Topic