Skip to content

Instantly share code, notes, and snippets.

Avatar
👑

Kim Branzell KimBranzell

👑
View GitHub Profile
View cloudSettings
{"lastUpload":"2021-09-07T07:45:55.177Z","extensionVersion":"v3.4.3"}
@KimBranzell
KimBranzell / function.php
Last active Feb 23, 2018
Get Luminance from background color and adjust text-color thereafter
View function.php
<?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);
View css-breakpoint-mixins.scss
@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 / functions.php
Last active Jun 17, 2016
Updates a post's slug whenever "Upload" or "Published" are pressed.
View functions.php
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 );
@KimBranzell
KimBranzell / functions.php
Last active May 22, 2016
Updates the parent CPT's (in a hierarchical CPT mode) last modified time to that of it's last modified child.
View functions.php
<?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 / [Wordpress] ACF checkbox value post display
Last active Aug 29, 2015
For when you want to loop and display posts based on the value of a checkbox.
View [Wordpress] ACF checkbox value post display
<?php
$args = array(
'meta_key' =>'your_checkboxkey',
'meta_value'=>'1'
);
$the_query = new WP_Query( $args );
?>
<!-- Loop continues here -->