Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other I have 8 header.php variations in WordPress. I must be doing something wrong.

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #35192
    xefned
    Member

    Every time I create a new page template in WordPress – for example category-news.php, or single-portfolio.php, I duplicate my header.php to call custom javascript libraries that won’t be used elsewhere on the site.

    so in category-news.php, I call my header like this: get_header(news);
    and in single-portfolio.php, I call my header like so: get_header(portfolio);

    Then I create header-news.php and header-portfolio.php in which 85% of the code is the same. Now when I want to make a single change to my header, I have to change it in multiple files. It seems like I MUST be doing something wrong.

    Is there a way to *extend* my header to keep “all the basics” + these two jquery plugins for a given post template?

    Thanks for any advice. A google search is making me feel like I’m the only person in the world who has this problem so I must be missing something obvious, Thank, Matth

    #90752
    standuncan
    Member

    Hmm… off the top of my head php variables is one way. An example:

    header.php







    single-portfolio.php (at top of document)



    '; ?>

    category-news.php (at top of document)



    '; ?>

    #90755
    xefned
    Member

    Genius! Thanks Stan.
    That’s exactly what I’m going to do. Thanks for the help.

    #90761
    standuncan
    Member

    There’s probably other ways as well, but that’s all I can think of right now though…

    #90762
    TheDoc
    Member

    I never, ever, ever have more than one header.php file.

    In my header.php I’ll do things like this:


    if ( is_page() ) {
    // do something
    }
    ?>

    It’s all about the conditionals. Here are all of the different ones you can use (there are a lot!): http://codex.wordpress.org/Conditional_Tags

    In your specific case, I would do something like this:


    if ( is_page_template( 'category-news.php' ) ) {
    // load your specific scripts
    }
    ?>
    #90763
    standuncan
    Member

    @TheDoc, are those WP specific?

    #90765
    TheDoc
    Member

    Yup!

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Other’ is closed to new topics and replies.