1

I have a difficult question. What's the best way to load a different header based on a post format? I guess I could load another loop around the header but I noticed the site does slow down. This is the code on my index.php:

<?php get_header();?>

<section id="block">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; endif; ?>

</section>

<?php get_footer();?>

Thanks

2
  • What do you need different header ( get_header() ) in single post format ? Commented Apr 27, 2016 at 4:28
  • 2
    "what is best?" type of questions are almost never good questions, best for what and when? please edit the question and try to be as specific as possible. For example you talk about a second loop, but don't show it... a second loop if done right in theory should not have any impact on noticeable performance Commented Apr 27, 2016 at 5:19

1 Answer 1

5

Say if your have header-video.php used for video post format.

Replace get_header(); with get_header(get_post_format()); in your regular singular.php or index.php. If WP can find header-video.php it will load it otherwise it will automatically will fallback to header.php.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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