Skip to content

Instantly share code, notes, and snippets.

@jo-flynn
Last active September 28, 2016 23:37
Show Gist options
  • Save jo-flynn/cf8968ed90e560094eb0e3684beef493 to your computer and use it in GitHub Desktop.
Save jo-flynn/cf8968ed90e560094eb0e3684beef493 to your computer and use it in GitHub Desktop.
<?php
$page_meta = new_cmb2_box([
'id' => 'page_meta',
'title' => 'Page Options',
'object_types' => ['page'],
'context' => 'normal',
'priority' => 'high',
'show_names' => true
]);
$page_meta->add_field([
'id' => 'via_mobile_featured',
'name' => 'Mobile Featured Image',
'desc' => "Add a header image for mobile devices only. Won't show without a featured image assigned.",
'type' => 'file',
'options' => [
'url' => false
],
]);
<?php
$mobile_thumbnail = get_post_meta($post->ID, 'via_mobile_featured', true);
$thumbnail = get_post_thumbnail_url('full');
?>
<style type="text/css">
<?php
if (!empty($mobile_thumbnail)) {
?>
.page-header {
background-image: url('<?php echo $mobile_thumbnail; ?>');
}
@media (min-width: 768px) {
.page-header {
background-image: url('<?php echo $thumbnail; ?>');
}
}
<?php
} else {
?>
.page-header {
background-image: url('<?php echo $thumbnail; ?>');
}
<?php
}
?>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment