0

I have a custom page template created. When I load my page, it shows the header logo of the mainpage but what I want to achieve is for each custom template created, I want it to only show its own logo.

This is the bit of the header code that calls the logo.php file:

<?php get_template_part('parts/logo', 'top') ?>

This is what I have tried but not working

<?php if ( is_page('custom-page')) {
    get_template_part ('parts/custom-logo', 'top');
} else {
    get_template_part('parts/logo', 'top');
} ?>

Any help will be much appreciated.

Thanks

  • 1
    Is the custom-logo-top.php file defined?? Seems you are not using the get_template_part the right way. Please check the Codex for details – Maruti Mohanty Mar 11 '14 at 6:30
  • hmm... hang on a minute, you might be right. I will take a look at this soon. Thanks for the response – Chelseawillrecover Mar 11 '14 at 6:32
1

As Maruti Mohanty mentioned you might not be using get_template_part in the correct way. The first argument is the slug name for the generic template. The second argument is the name of the specialized template. So currently your code is doing the following:

  • On the page that has the 'custom-page' slug, display the template part named custom-logo-top.php.
  • If that file doesn't exist then just display the generic template part called custom-logo.php

I'd probably name your template parts 'logo.php' and 'logo-custom.php'. It's worth having a look through the Twenty Fourteen theme that comes with Wordpress as well as the codex whenever you're unsure of anything.

  • yes he was right, I followed the same format the Theme owner wrote and that mislead me. So I had to remove top from mine and replaced it with logo since my file name was custom-logo.php and not custom-logo-top.php – Chelseawillrecover Mar 11 '14 at 8:06

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.