Skip to content

Instantly share code, notes, and snippets.

Array
(
[payment_method] => invoice
[currency] => nok
[invoice_address_1] => Mistelteinen 31
[invoice_zipcode] => 3154
[invoice_city] => Tønsberg
[invoice_email] => [email protected]
[invoice_firstname] => Michaeli
[invoice_lastname] => Wilhelmsenia
@michaelwilhelmsen
michaelwilhelmsen / acf_dynamic_gutenberg_fontsizes_load.php
Last active July 20, 2023 13:54
A good use for this is when you need more granular control of font sizes in ACF Blocks within repeaters and flexible fields. Instead of using the default Gutenberg font size attribute, you can dynamically load all the font sizes defined by your theme in theme.json
<?php
add_filter('acf/load_field/name=font_size_gutenberg', 'sp_acf_dynamic_fontsizes_load');
function sp_acf_dynamic_fontsizes_load($field) {
// get array of colors created using editor-color-palette
$font_sizes = wp_get_global_settings()['typography']['fontSizes']['theme'];
// if this array is empty, continue
if (!empty($font_sizes)) {
# custom rules for loading server images or any other uploaded media files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$
RewriteRule ^(.*)$ https://site.com/$1 [QSA,L]
@michaelwilhelmsen
michaelwilhelmsen / hover-on-touch.js
Created October 3, 2019 12:25
Mobile hover often does not register correctly. Add this one-liner to your scripts to make touches automatically trigger a hover-event.
document.addEventListener("touchstart", function() {}, false);
extends Camera2D
var _duration = 0.0
var _period_in_ms = 0.0
var _amplitude = 0.0
var _timer = 0.0
var _last_shook_timer = 0
var _previous_x = 0.0
var _previous_y = 0.0
var _last_offset = Vector2(0, 0)
@michaelwilhelmsen
michaelwilhelmsen / enqueue_if_acf_field_is_used.php
Last active January 29, 2019 15:04
This works even for flexible content fields. Just inspect the field in console when in admin and snab the data-key name from there.
<?php
add_action( 'wp_enqueue_scripts', 'sp_register_acf_field_scripts', 5 );
function sp_register_acf_field_scripts() {
// Plugin file
wp_register_script( 'siema-js', get_stylesheet_directory_uri() . '/bower_components/siema/dist/siema.min.js', array(), '', true );
// Custom functionality
wp_register_script( 'siema-init-js', get_stylesheet_directory_uri() . '/library/js/siema-init.js', array(), '', true );
}
@michaelwilhelmsen
michaelwilhelmsen / age-check.js
Last active June 29, 2017 12:19
Lity Popup Age Check with cookie functionality. Deny access to site if user is not over the age of 18. Dependencies: - lity.js - js-cookie.js - jquery
jQuery(document).ready(function($) {
// If #agecheck exists
if ($('#agecheck').length) {
function isOverEighteen() {
// Define cookie
Cookies.set('over-eighteen');
// Open popup if cookie value is set to "no" or if cookie is undefined
if (Cookies.get('over-eighteen') == 'no' || Cookies.get('over-eighteen') == undefined) {
var ageCheckLity = lity($('#agecheck'), {
@michaelwilhelmsen
michaelwilhelmsen / modern-responsive-header-768up.scss
Last active June 23, 2017 11:35
Full Responsive Header. Mobile: Left-aligned nav toggle, centered logo, right-aligned search Desktop: Left-aligned logo, centered navigation list items, right-aligned search
/*********************
HEADER STYLES
*********************/
.header {
#inner-header {
justify-content: space-between;
}
}
@michaelwilhelmsen
michaelwilhelmsen / add_taxonomy_filters.php
Created June 12, 2017 09:00
Adds filter select box for custom post types in admin. Change $typenow to post-type, $taxonomies to the taxonomy-category/slug.
// FILTERING IN ADMIN
function sp_add_taxonomy_filters() {
global $typenow;
// an array of all the taxonomies you want to display. Use the taxonomy name or slug
$taxonomies = array('publikasjoner_category');
// must set this to the post type you want the filter(s) displayed on
if( $typenow == 'publikasjoner' ){
@michaelwilhelmsen
michaelwilhelmsen / if_last_modified.php
Created February 16, 2017 08:20
Add Last-Modified headers.
add_action('template_redirect', 'sp_add_last_modified_header');
function sp_add_last_modified_header($headers) {
//Check if we are in a single post of any type (archive pages has not modified date)
if( is_singular() ) {
$post_id = get_queried_object_id();
if( $post_id ) {
header("Last-Modified: " . get_the_modified_time("D, d M Y H:i:s", $post_id) );
}
}
}