Skip to content

Instantly share code, notes, and snippets.

@humayunahmed8
Created September 15, 2018 12:10
Show Gist options
  • Save humayunahmed8/6a386fa6bac6f21f4a80fb2b8092b762 to your computer and use it in GitHub Desktop.
Save humayunahmed8/6a386fa6bac6f21f4a80fb2b8092b762 to your computer and use it in GitHub Desktop.
Logo setting option using codestar framwork
<?php
function stock_humayunbd_page_metabox($options){
$options = array(); // remove old options
// Logo Setting
$options[] = array(
'name' => 'stock_humayunbd_logo_settings',
'title' => esc_html__('Logo Settings','stock-humayunbd'),
'icon' => 'fa fa-heart',
'fields' => array(
array(
'id' => 'enable_image_logo',
'type' => 'switcher',
'title' => esc_html__('Enable image logo','stock-humayunbd'),
'default' => false,
),
array(
'id' => 'image_logo',
'type' => 'image',
'title' => esc_html__('Upload logo','stock-humayunbd'),
'dependency' => array( 'enable_image_logo', '==', 'true' ),
),
array(
'id' => 'image_logo_max_width',
'type' => 'text',
'default' => esc_attr('200','stock-humayunbd'),
'title' => esc_html__('Logo max width','stock-humayunbd'),
'desc' => esc_html__('Type logo max width as numeric value','stock-humayunbd'),
'dependency' => array( 'enable_image_logo', '==', 'true' ),
),
array(
'id' => 'text_logo',
'type' => 'text',
'title' => esc_html__('Logo text','stock-humayunbd'),
'default' => esc_html__('Stock','stock-humayunbd'),
'dependency' => array( 'enable_image_logo', '==', 'false' ),
),
)
);
return $options;
}
add_filter( 'cs_metabox_options', 'stock_humayunbd_page_metabox' );
<?php
/**
* Query logo setting option from database
*
*/
// Store framework data
$enable_image_logo = cs_get_option('enable_image_logo');
$image_logo = cs_get_option('image_logo');
$image_logo_max_width = cs_get_option('image_logo_max_width');
$text_logo = cs_get_option('text_logo');
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php if($enable_image_logo == true && !empty($image_logo)) :
$image_logo_src = wp_get_attachment_image_src( $image_logo, 'large', false );
?>
<img style="max-width:<?php echo esc_attr($image_logo_max_width); ?>px" src="<?php echo esc_url($image_logo_src[0]); ?>" alt="<?php echo esc_html(bloginfo( 'name' )); ?>">
<?php else : ?>
<?php if(!empty($text_logo)) {echo esc_html($text_logo);} else{ echo esc_html(bloginfo( 'name' ));} ?>
<?php endif; ?>
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment