Created
April 26, 2024 02:58
-
-
Save David-Melo/16b5e0470c9fe03b86e8d1a8e65174a4 to your computer and use it in GitHub Desktop.
ACF Example Shortcode
This file contains hidden or 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
<?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