Skip to content

Instantly share code, notes, and snippets.

View morgyface's full-sized avatar

Dan morgyface

View GitHub Profile
@morgyface
morgyface / sanitize.njk
Created February 3, 2021 15:07
Nunjucks | sanitize | replace whitespace with hyphens
{% set image = profile.name | lower | replace(" ", "-") %}
@morgyface
morgyface / archive_tax_name.php
Created December 17, 2020 10:04
WordPress get the singular name of the taxonomy the term archive belongs to
<?php
function archive_tax_name() {
$archive_tax_name = null;
if( is_archive() && is_category() ) {
$queried_object = get_queried_object();
$queried_object_taxonomy = $queried_object->taxonomy;
$taxonomy = get_taxonomy($queried_object_taxonomy);
$archive_tax_name = $taxonomy->labels->singular_name;
}
return $archive_tax_name;
@morgyface
morgyface / add_the_categories.php
Created November 25, 2020 17:21
WordPress | Add categories programmatically on theme activation
<?php
// Sets the default categories
function add_the_categories() {
$categories = array(
'Case Study',
'Blog',
'Article'
);
foreach( $categories as $category ) {
$exists = term_exists( $category, 'category' );
@morgyface
morgyface / social_icons_16.html
Last active November 30, 2025 11:49
Social icons at 16 pixels high
<svg class="facebook" xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<path fill="#1877f2" d="M16 8c0-4.4-3.6-8-8-8S0 3.6 0 8c0 4 2.9 7.3 6.8 7.9v-5.6h-2V8h2V6.2c0-2 1.2-3.1 3-3.1.9 0 1.8.2 1.8.2v2h-1c-1 0-1.3.6-1.3 1.2V8h2.2l-.4 2.3H9.2v5.6C13.1 15.3 16 12 16 8z"/>
</svg>
<svg class="twitter" xmlns="http://www.w3.org/2000/svg" width="20" height="16">
<path fill="#1da1f2" d="M6.2 16c7.4 0 11.5-6.2 11.5-11.5V4c.8-.6 1.5-1.3 2-2.1-.7.3-1.5.5-2.3.6.8-.5 1.5-1.3 1.8-2.2-.8.5-1.7.8-2.6 1-1.5-1.6-4.1-1.7-5.7-.2-1 1-1.5 2.5-1.2 3.9C6.4 4.8 3.4 3.3 1.4.7.3 2.6.8 4.9 2.6 6.1c-.6 0-1.3-.2-1.8-.5v.1c0 1.9 1.4 3.6 3.2 4-.6.1-1.2.1-1.8 0 .5 1.6 2 2.8 3.8 2.8-1.4 1.1-3.2 1.7-5 1.7-.3 0-.6 0-1-.1C1.8 15.4 4 16 6.2 16"/>
</svg>
<svg class="linkedin" xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<path fill="#0a66c2" d="M14.8 0H1.2C.5 0 0 .5 0 1.2v13.7c0 .6.5 1.1 1.2 1.1h13.6c.6 0 1.2-.5 1.2-1.2V1.2c0-.7-.5-1.2-1.2-1.2zM6.2 6h2.3v1c.5-.8 1.4-1.2 2.3-1.2 2.4 0 2.8 1.6 2.8 3.6v4.2h-2.4V9.9c0-.9 0-
@morgyface
morgyface / social_icons_20.html
Last active November 30, 2025 11:50
Social icons at 20 pixels high
<div class="social">
<svg class="facebook" xmlns="http://www.w3.org/2000/svg" width="20" height="20">
<path fill="#1877f2" d="M20 10c0-5.5-4.5-10-10-10S0 4.5 0 10c0 5 3.7 9.1 8.4 9.9v-7H5.9V10h2.5V7.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V10h2.8l-.4 2.9h-2.3v7C16.3 19.1 20 15 20 10z" />
</svg>
<svg class="linkedin" xmlns="http://www.w3.org/2000/svg" width="20" height="20">
<path fill="#0a66c2" d="M18.5 0h-17C.7 0 0 .6 0 1.4v17.1c0 .9.7 1.5 1.5 1.5h17c.8 0 1.5-.6 1.5-1.4V1.4c0-.8-.7-1.4-1.5-1.4zM7.8 7.5h2.8v1.3c.6-1 1.7-1.6 2.8-1.5 3 0 3.6 2 3.6 4.5V17h-3v-4.6c0-1.1 0-2.5-1.5-2.5s-1.8 1.2-1.8 2.5V17h-3V7.5zM4.4 2.8c.9 0 1.7.8 1.7 1.7s-.7 1.7-1.7 1.7c-.9 0-1.7-.8-1.7-1.7 0-1 .8-1.7 1.7-1.7zm1.5 4.7V17H3V7.5h2.9z" />
</svg>
@morgyface
morgyface / eleventy_dates.njk
Created May 26, 2020 10:34
11ty | Dates | Nunjucks
<span class="approval__date">{{ item.designDate.toDateString().slice(4, -5) }}</span>
@morgyface
morgyface / slice.njk
Created May 12, 2020 11:27
Nunjucks | 11ty | Truncate, trim or slice. Return part of a string in nunjucks
{{ set cats = "meowers" }}
{{ cats.slice(1, -1) }}
{# Returns: eower #}
{{ cats.slice(3) }}
{# Returns: wers #}
{{ set dogs = " woofers " }}
{{ dogs | trim }}
@morgyface
morgyface / string_md_array.php
Created May 6, 2020 11:20
PHP | Comma seperated string into ACF compatible multidimensional array
<?php
$string = "Skateboarding, Surfing, Horseriding"; // The original comma seperated string
$columns = explode(", ", $string); // Turns the string into an array
$column_array = array(); // Sets up the outer array
foreach ($columns as $key => $value) {
// Loops through the array creating keys and values
$column_array[$key]['skill'] = $value;
// $column_array[$key]['level'] = '0';
}
@morgyface
morgyface / wp-login-styles.php
Last active October 21, 2020 15:12
WordPress | Login customisation
<?php
// Add the login styles
function add_login_scripts() {
/**
* login_enqueue_scripts is the proper hook to use when enqueuing items that
* are meant to appear on the login page.
*/
wp_enqueue_style( 'core', get_stylesheet_directory_uri() . '/assets/css/login.min.css', array('login') );
}
add_action( 'login_enqueue_scripts', 'add_login_scripts' );
@morgyface
morgyface / allow_svg.php
Created May 3, 2020 19:34
WordPress | Allow SVG files
<?php
// Add SVG to allowed file uploads
function add_file_types_to_uploads($file_types){
$new_filetypes = array();
$new_filetypes['svg'] = 'image/svg';
$file_types = array_merge($file_types, $new_filetypes );
return $file_types;
}
add_action('upload_mimes', 'add_file_types_to_uploads');