Skip to content

Instantly share code, notes, and snippets.

View chekle's full-sized avatar

Cheyne chekle

View GitHub Profile
@chekle
chekle / gist:6b6129bf6b3575bcc629d19d82da1cc9
Last active May 31, 2023 01:19
Style a select element - CSS
select{
font-size:22px;
font-size: 2.2rem;
font-size: clamp(1.8rem, 6vw, 2.2rem);
padding:5px 15px;
display: block;
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48IS0tISBGb250IEF3ZXNvbWUgUHJvIDYuNC4wIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlIChDb21tZXJjaWFsIExpY2Vuc2UpIENvcHlyaWdodCAyMDIzIEZvbnRpY29ucywgSW5jLiAtLT48cGF0aCBkPSJNMjM5IDQwMWM5LjQgOS40IDI0LjYgOS40IDMzLjkgMEw0NjUgMjA5YzkuNC05LjQgOS40LTI0LjYgMC0zMy45cy0yNC42LTkuNC0zMy45IDBsLTE3NSAxNzVMODEgMTc1Yy05LjQtOS40LTI0LjYtOS40LTMzLjkgMHMtOS40IDI0LjYgMCAzMy45TDIzOSA0MDF6IiBmaWxsPSIjZmZmZmZmIi8+PC9zdmc+');
<?php $args = array(
'post_type' => 'post',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => 3,
);
$query = new WP_Query( $args ); ?>
<?php if ( $query->have_posts() ) { ?>
@chekle
chekle / gist:e653a9370c6b9db001c4c3c80d4fbf0f
Created June 1, 2023 04:08
Background images using - ACF / CSS
style="background-image:url('<?php $image = get_sub_field('image'); $size = 'full'; if( $image ) { echo wp_get_attachment_image_url( $image, $size ); } ?>');"
style="background-image: linear-gradient(269.77deg, rgba(0, 0, 0, 0.2) 2.1%, rgba(0, 0, 0, 0.6) 100%), url(<?php $image = get_sub_field('background_image'); $size = 'full'; if( $image ) { echo wp_get_attachment_image_url( $image, $size ); } ?>);"
/* Background Images CSS */
background-image:url(images/image.jpg);
background-repeat: no-repeat;
background-size:cover;
@chekle
chekle / gist:c73a4d8de7b5e447001e7dfc643efaa0
Created June 29, 2023 23:14
Background Image Sizing using aspect ratio
aspect-ratio: 16 / 9;
.image{
aspect-ratio: 16 / 11;
background-repeat: no-repeat;
background-size:contain;
background-position:center;
}
This essentially makes a background image work proportionally across responsive/different screen sizes without having to set the height at each different breakpoint.
<?php $link = get_sub_field('link'); if( $link ): $link_url = $link['url']; $link_title = $link['title']; $link_target = $link['target'] ? $link['target'] : '_self'; ?>
<a class="button" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
<?php endif; ?>
@chekle
chekle / gist:78af18c95889da42869c66e1ea4be38f
Last active November 20, 2023 03:08
ACF Images Using ID
URL
<?php $image = get_sub_field('image'); $size = 'medium'; if( $image ) { echo wp_get_attachment_image_url( $image, $size ); } ?>
IMG
<?php $image = get_sub_field('image'); $size = 'full'; if( $image ) { echo wp_get_attachment_image( $image, $size ); } ?>
IMG w Class
<?php $image = get_sub_field('image'); $size = 'full'; if( $image ) { echo wp_get_attachment_image( $image, $size, "", array ('class' => 'rounded-4 mb-4' ) ); } ?>
FIGURE / IMG
@chekle
chekle / gist:b8422fa39d53aace190b9834cf1b6554
Created July 5, 2023 01:30
Clamp - Simple CSS Clamp Example
font-size: 48px;
font-size: 4.8rem;
font-size: clamp(3.8rem, 6vw, 4.8rem);
@chekle
chekle / gist:304e40f7a8120cf5eb5ff94f58d9089b
Created July 5, 2023 20:50
Custom colours swatches for WordPress WYSIWYG
/* ================== Custom colors swatches ======================== */
function my_mce4_options($init) {
$custom_colours = '
"496125", "Pounamu Green",
"F4EDD4", "Whenua",
"01AEF0", "Purū-pōuri",
"305C7D", "Kōwhai",
"EECE63", "Kōwhai 50%",
"ADC6ED", "Ōrangitea",
@chekle
chekle / gist:bf71d51d0ea8c7584c34baa6f3f3ce22
Created July 6, 2023 06:39
WordPress Featured Image Examples
// Enable featured images for blog posts
add_theme_support( 'post-thumbnails' );
// Enable for specific CPT or Events Calendar
add_theme_support( 'post-thumbnails', [
'post',
'page',
'tribe_events',
@chekle
chekle / gist:5d7934e2bc9fe559cd53ce0dddc05a57
Created July 6, 2023 06:48
WordPress Shortcode Examples
WORDPRESS DO SHORTCODE
<?php echo do_shortcode("[shortcode]"); ?>
SHORTCODE FROM ACF FIELD
<?php echo do_shortcode(get_field('social_stream_shortcode')); ?>
GFORMS
<?php echo do_shortcode("[gravityform id='1' title='false' description='false' ajax='true']"); ?>
[gravityform id="1" title="false" description="false" ajax="true"]