Support

Account

Home Forums ACF PRO Image-Not-Available option Reply To: Image-Not-Available option

  • No worries! You may do either a theme or plugin, depending on how you are adding this functionality. Let’s assume you are modifying a theme, in which case you could add the following to functions.php:

    
    if( function_exists('acf_add_options_page') ) {
     
    	$option_page = acf_add_options_page(array(
    		'page_title' 	=> 'Theme General Settings',
    		'menu_title' 	=> 'Theme Settings',
    		'menu_slug' 	=> 'theme-general-settings',
    		'capability' 	=> 'manage_options',
    		'redirect' 	=> false
    	));
     
    }
    

    Then you can setup a new field group in ACF, and select as a Rule to display the field group: Options Page is equal to <Your Options Page Name>.
    In this field group you would add another image field, for the default image.

    Finally, you may modify your code above as follows:

    
    <?php 
    
    // First try the image you want
    $image = get_field('photo102');
    if( empty($image) ): 
        // If that doesn't work, try to get the Option Page setting
        $image = get_field('photo_alternate', 'option');
    endif;
    
    // Now check for existence of either option having worked
    if( !empty($image) ):
    	// vars
    	$url = $image['url'];
    	$title = $image['title'];
    	$alt = $image['alt'];
    	$caption = $image['caption'];
    
    	// thumbnail
    	$size = 'member-listing';
    	$thumb = $image['sizes'][ $size ];
    	$width = $image['sizes'][ $size . '-width' ];
    	$height = $image['sizes'][ $size . '-height' ];
    
    	if( $caption ): ?>
    
    		<div class="wp-caption">
    
    	<?php endif; ?>
    
    	 <!--  see single-cdtxprofessional.php in this area for code for adding link to picture itself if you want that -->
    
    		<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
    
    	</a>
    
    	<?php if( $caption ): ?>
    
    			<p class="wp-caption-text"><?php echo $caption; ?></p>
    
    		</div>
    
    	<?php endif; ?>
    
    <?php endif; ?>
    

    ————————-

    Help your fellow forum-goers and moderation team; if a response solves your problem, please mark it as the solution. Thank you!