Skip to content

Instantly share code, notes, and snippets.

@dospuntocero
Created October 5, 2020 10:50
Show Gist options
  • Save dospuntocero/af5adf5519b8a187a0295cf0adae64fa to your computer and use it in GitHub Desktop.
Save dospuntocero/af5adf5519b8a187a0295cf0adae64fa to your computer and use it in GitHub Desktop.
passing parameters to wordpress's get_template_part on version 5.5+
//the third variable is an array where you can pass any variables or complete objects
<?php get_template_part('template-parts/featured-image',null,[
'subHead' => get_field('title_sub-head')
]); ?>
//in the part, you use the key $args to pass the parameters.
<?php if ( has_post_thumbnail( $post->ID ) ) : ?>
<section class="hero" style="background-image: url(<?php the_post_thumbnail_url(); ?>);">
<?php echo $args['subHead']; // here you pass the arguments with the variable $args?>
</section>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment