I am trying to display some elements in a template file when a user clicks a button, specifically an image gallery and another separate template part. The following doesn't break the site but doesn't work either,
<div>
<button onclick="myFunction()" id="loadOverlays" type="button">LOAD OVERLAYS</button>
</div>
<script>
function myFunction() {
<div>
<?php
$item_id = get_the_ID();
$tags = get_the_terms( $item_id, 'attachment_tag' );
$slug = '';
foreach ( $tags as $tag ) {
if ( 0 === strpos( $tag->name, 'Portrayal:' ) ) {
$slug = 'overlay' . substr( $tag->slug, strlen( 'portrayal' ));
break;
}
}
if ( !empty( $slug ) ) {
echo do_shortcode( sprintf( '[mla_gallery attachment_tag="%1$s" ]', $slug ) );
}
?>
</div>
<?php get_template_part( 'exn', 'overlays' ); ?>
}
</script>
It needs some magic sauce to force it to actually display.
Thanks,