0

I have tried adding a file inside my header.php, but it will not load correctly. I get this error:

Fatal error: Uncaught Error: Call to undefined function get_tempalte_part()

Here is my markup in my header.php:

<html class="m-0">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>*TITLE*</title>
        <?php wp_head(); ?>
    </head>

    <body <?php body_class(); ?> >

            <section id="header" class="container-fluid no-gutters">

                <?php
                if( is_page( 'blog' ) ) {
                    get_template_part( 'inc/fd-', 'blog' );
                } else {
                    get_tempalte_part( 'inc/fd-', 'default' );
                }
                ?>

                <?php if( is_search() ) {
                    fd_title_search();
                } else if( is_product() || is_account_page() || is_page( 'contact-us' ) || is_page( 'shipping' ) || is_page( 'privacy' ) || is_page( 'terms' ) || is_page( 'faq' ) || is_page( 'about-us' ) || is_page( 'home' ) ) {
                    echo '';
                } else if( is_product_category() ) {
                    fd_title_product_category();
                } else if( is_shop() ) {
                    fd_title_shop();
                } else if( is_page( 'wishlist' ) ) {
                    fd_title_wishlist();
                } else {
                    fd_title_default();
                } ?>

            </section>

I am trying to load fd-blog.php if it is the 'Blog' page, otherwise load the fd-default.php, but I keep getting an error, no matter what I try! What am I doing wrong?

  • 1
    This doesn't answer the question, but there's no need for the dash (-). Just inc/fd as in get_template_part( 'inc/fd', 'blog' ); – Sally CJ Jul 24 at 8:29
  • 1
    And there's a typo: get_tempalte_part - that should be get_template_part - in get_tempalte_part( 'inc/fd-', 'default' ); – Sally CJ Jul 24 at 8:34
  • 1
    @SallyCJ, It actually helped solve my problem! One was the typo (how embarrassing) and the other was the unnecessary trailing dash! All working! Please submit it as an answer so I can mark it accordingly. – Jesse Jul 24 at 8:42
3

This is just a supplement to the other answer.

I am trying to load fd-blog.php if it is the 'Blog' page, otherwise load the fd-default.php

To actually load the template file, you should remove the dash (-):

get_template_part( 'inc/fd', 'blog' );    // loads inc/fd-blog.php
get_template_part( 'inc/fd', 'default' ); // loads inc/fd-default.php

So just inc/fd, and here's the relevant code in get_template_part:

// Example when you call get_template_part( 'inc/fd', 'blog' ), $name below is 'blog'.
if ( '' !== $name ) {
    $templates[] = "{$slug}-{$name}.php";
}
1

You've spelt it wrong: get_tempalte_part, "tempalte", needs to be get_template_part().

  • Well, that's embarrassing...lol – Jesse Jul 24 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.