Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save PurpleHippoDesign/6e039e54d4869da94ce5 to your computer and use it in GitHub Desktop.
Save PurpleHippoDesign/6e039e54d4869da94ce5 to your computer and use it in GitHub Desktop.
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