Skip to content

Instantly share code, notes, and snippets.

View KimBranzell's full-sized avatar
👑

Kim Branzell KimBranzell

👑
View GitHub Profile
@KimBranzell
KimBranzell / [Wordpress] ACF checkbox value post display
Last active August 29, 2015 14:15
For when you want to loop and display posts based on the value of a checkbox.
<?php
$args = array(
'meta_key' =>'your_checkboxkey',
'meta_value'=>'1'
);
$the_query = new WP_Query( $args );
?>
<!-- Loop continues here -->
@KimBranzell
KimBranzell / functions.php
Last active May 22, 2016 22:42
Updates the parent CPT's (in a hierarchical CPT mode) last modified time to that of it's last modified child.
<?php
add_action( 'save_post','changeLastModified' );
function changeLastModified( $post ){
if ( 'YOUR_CUSTOM_POST_TYPES_NAME' == get_post_type( $post ) ) {
if( ! ( wp_is_post_revision( $post ) ) ) {
$sync_time = array();
$sync_time['ID'] = wp_get_post_parent_id( $post );
$sync_time['post_modified'] = get_post_field( 'post_modified', $post, 'raw' );
remove_action( 'save_post', 'changeLastModified' );
wp_update_post( $sync_time, true );
@KimBranzell
KimBranzell / functions.php
Last active June 17, 2016 09:16
Updates a post's slug whenever "Upload" or "Published" are pressed.
function update_post_slug( $data, $postarr ) {
if ( ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
$data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'] ), $postarr['ID'], $data['post_status'], $data['post_type'], $data['post_parent'] );
}
return $data;
}
add_filter( 'wp_insert_post_data', 'update_post_slug', 99, 2 );
@mixin for-phone-only {
@media (max-width: 599px) { @content; }
}
@mixin for-tablet-portrait-up {
@media (min-width: 600px) { @content; }
}
@mixin for-tablet-portait-only {
@media (min-width: 600px) and (max-width: 899px) { @content; }
}
@mixin for-tablet-landscape-up {
@KimBranzell
KimBranzell / function.php
Last active February 23, 2018 09:57
Get Luminance from background color and adjust text-color thereafter
<?php
function getLuminance($val) {
$hex = $val;
// Get int RGB values from the hex.
list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
// Calculate according to the formula
$red = 0.2126 * ($r/255);
$green = 0.7152 * ($g/255);
{"lastUpload":"2021-09-07T07:45:55.177Z","extensionVersion":"v3.4.3"}
@KimBranzell
KimBranzell / gist:4645d0e5f0c4cc07aa665c4da39195c5
Created January 12, 2023 13:51
This mixin calculates the closest best possible contrast for a given text color according to WCAG (Web Content Accessibility Guidelines) standards.
@mixin best-contrast($text-color, $bg-color, $level) {
$lum1: luminance($text-color);
$lum2: luminance($bg-color);
$contrast: $lum1 / $lum2;
@if $contrast < 1 {
$contrast: 1 / $contrast;
}
@if $level == AA {
@if $contrast < 4.5 {
// Text color does not meet AA contrast ratio, adjust color

Keybase proof

I hereby claim:

  • I am KimBranzell on github.
  • I am brnzl (https://keybase.io/brnzl) on keybase.
  • I have a public key whose fingerprint is 5BCA 6FB2 A0E2 0938 07DD 114E 1374 3D36 0F45 BD22

To claim this, I am signing this object: