Skip to content

Instantly share code, notes, and snippets.

@ScarletPonytail
Created August 31, 2018 14:32
Show Gist options
  • Save ScarletPonytail/3311c6f2153f273c766448ef259c5e62 to your computer and use it in GitHub Desktop.
Save ScarletPonytail/3311c6f2153f273c766448ef259c5e62 to your computer and use it in GitHub Desktop.
PHP - Make image a link for SC.com
<?php // Make the image a link
if ( 'yes' === $settings->cb_blk_one_show_btns ) :
// Run a foreach loop over every button from global options
if ( count( $settings->cb_blk_one_btns ) === 1 ) :
foreach ( $settings->cb_blk_one_btns as $key => $val ) :
printf( '<a href="%1$s" class="ctawrapa %2$s" target="%3$s" %4$s>',
( strpos( $settings->cb_blk_one_btns[ $key ]->sc_global_urltype, 'open-country-popup' ) !== false ) ? esc_attr( '#country-popup' ) : esc_url( $settings->cb_blk_one_btns[ $key ]->sc_global_btnurl ), // %1$s : href
( ( strpos( $settings->cb_blk_one_btns[ $key ]->sc_global_urltype, 'open-country-popup' ) !== false ) ? esc_attr( 'country-popup' ) : '' ), // %2$s : Add country-popup class for JS listener
( ( strpos( $settings->cb_blk_one_btns[ $key ]->sc_global_urltype, 'open-country-popup' ) === false ) ? esc_url( $settings->cb_blk_one_btns[ $key ]->sc_global_urltype ) : '' ), // %3$s : If not country popup as target (_self, _blank)
( ( strpos( $settings->cb_blk_one_btns[ $key ]->sc_global_urltype, 'open-country-popup' ) !== false ) ? 'data-location="' . esc_attr( '' . str_replace('open-country-popup-', '', $settings->cb_blk_one_btns[ $key ]->sc_global_urltype) ) . '"' : '' ) // %4$s : Set country popup style so be used in JS (personal, business, islamic...)
);
endforeach;
endif;
endif; ?>
<?php if ( ! empty( $settings->cb_blk_one_img ) ) : // Does this have an image?
add_filter( 'wp_calculate_image_srcset_meta', '__return_null' );
echo wp_get_attachment_image( $settings->cb_blk_one_img , 'content-block' );
remove_filter( 'wp_calculate_image_srcset_meta', '__return_null' );
endif; ?>
<?php // Make the image a link
if ( 'yes' === $settings->cb_blk_one_show_btns ) : // Check if the buttons should show
if ( count( $settings->cb_blk_one_btns ) === 1 ) : ?>
</a>
<?php endif;
endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment