Created
October 5, 2020 10:50
-
-
Save dospuntocero/af5adf5519b8a187a0295cf0adae64fa to your computer and use it in GitHub Desktop.
passing parameters to wordpress's get_template_part on version 5.5+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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