Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Removing ACF front end dependency
<?php
$gallery = get_post_meta( get_the_ID(), 'gallery' ); // 'gallery' is name of my ACF gallery field
if( is_array( $gallery[0] )) {
$image_ids = $gallery[0];
$shortcode = '[gallery columns="3" link="none" size="large" ids="' . implode(',', $image_ids) . '"]'; // build your gallery shortcode
echo do_shortcode( $shortcode );
}
<?php
$bg_image = get_post_meta( get_the_ID(), 'hero', true );// 'hero' is name of my ACF gallery field
$image_url = wp_get_attachment_url( $bg_image ); //get the image url
if ( $bg_image ) {
echo '<section class="hero-section" style="background-image:url('.$image_url.'); background-repeat:no-repeat;">
</div">';
}
<?php
$url = esc_url( get_post_meta( get_the_ID(), 'my_url', true )); //'my_url' is name of my ACF url field
if ($url) {
echo '<a href="'.$url. '" class="button">Visit Link</a>';
}
<?php
$mycontent = wpautop (get_post_meta( get_the_ID(), 'test_wysiwyg', true )); // 'test_wysiwyg' is name of my ACF wysiwyg field
if ($mycontent) {
echo '<div class="row">' . $mycontent . '</div>';
}
<?php
$location = wpautop (get_post_meta( get_the_ID(),'location', true));
$location = apply_filters('the_content', $location); //Apply filter to initiate shortcodes
if ( $location ) {
echo '<div class="location-map">' . $location. '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.