Skip to content

Instantly share code, notes, and snippets.

@David-Melo
Created April 26, 2024 02:58
Show Gist options
  • Save David-Melo/16b5e0470c9fe03b86e8d1a8e65174a4 to your computer and use it in GitHub Desktop.
Save David-Melo/16b5e0470c9fe03b86e8d1a8e65174a4 to your computer and use it in GitHub Desktop.
ACF Example Shortcode
<?php
function style_partners_grid() {
wp_enqueue_style( 'style_partners_grid', get_stylesheet_directory_uri() . '/css/partners.css' );
}
add_action( 'wp_enqueue_scripts', 'style_partners_grid' );
function shortcode_partners_grid($params = array()) {
$_id = time();
ob_start();
//echo time();
$styles = [];
// ---------------------------------------------------------------------------------------------------
echo "<div class='partners'>";
$partners_images = get_field( 'partners', 'option' );
if ( $partners_images ) :
foreach ( $partners_images as $partners_image ):
$url = $partners_image['url'];
$alt = $partners_image['alt'];
echo "<div class='partners-item'>";
echo "<img src='$url' alt='$alt' />";
echo "</div>";
endforeach;
endif;
echo "</div>";
// -----------------------------------------------------------------------------------------------
echo "<style type='text/css'>";
echo implode('',$styles);
echo "</style>";
wp_reset_query();
return ob_get_clean();
}
add_shortcode('partners', 'shortcode_partners_grid');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment