Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
aaronsummers / mega-menu-walker.php
Last active May 19, 2022 10:01
WordPress mege menu with featured images and alternative layout if the menu contains more than 4 items
<?php
/**
* Nav Menu API: Walker_Nav_Menu class
*
* @package WordPress
* @subpackage Nav_Menus
* @since 4.6.0
*/
/**
@aaronsummers
aaronsummers / sed.md
Created April 11, 2022 13:47
How to Use sed to Find and Replace String in Files

https://linuxize.com/post/how-to-use-sed-to-find-and-replace-string-in-files/

When working with text files, you’ll often need to find and replace strings of text in one or more files.

sed is a stream editor. It can perform basic text manipulation on files and input streams such as pipelines. With sed, you can search, find and replace, insert, and delete words and lines. It supports basic and extended regular expressions that allow you to match complex patterns.

In this article, we’ll talk about how to find and replace strings with sed. We’ll also show you how to perform a recursive search and replace.

Find and Replace String with sed #

@aaronsummers
aaronsummers / document-ready-function.js
Created December 6, 2021 11:14
Javascript Document Ready
// https://stackoverflow.com/questions/45291962/vanilla-js-version-of-jquery-document-on-click-for-links#answer-45292145
function addEvent(parent, evt, selector, handler) {
parent.addEventListener(evt, function(event) {
if (event.target.matches(selector + ', ' + selector + ' *')) {
handler.apply(event.target.closest(selector), arguments);
}
}, false);
}
/* To be used as */
@aaronsummers
aaronsummers / multidimentional-array.php
Last active July 15, 2021 14:18
Create an array of arrays, building a multidimentional array with an array
<?php
/*
The important thing here is having 2x empty arrays.
The first array is the parent - level 1 array
The second array is the child - level 2 array
*/
$examples = array(
'item 1',
'item 2',
'item 3',
@aaronsummers
aaronsummers / add search to menu.php
Created June 14, 2021 13:31
add search to menu in wordpress via functions
<?php
/**
* ANCHOR Add search box to primary menu
*/
function elab_nav_search($items, $args) {
// If this isn't the primary menu, do nothing
if ( !($args->theme_location == 'primary') ) :
return $items;
endif;
// Otherwise, add search form
@aaronsummers
aaronsummers / guttenburg-colours.css
Created May 17, 2021 07:37
Guttenburg - Add custom colours
/** ANCHOR Custom colours for Gutenberg editor */
/** Blue colours **/
.has-blue-background-color {
background-color: #009aa9;
}
.has-blue-color {
color: #009aa9;
}
@aaronsummers
aaronsummers / day-of-the-week.php
Last active May 5, 2021 08:47
Get the day of the week from the date with php
<?php
$date = date('Y-m-d');
$dayOfWeek = date("l", strtotime($date));
@aaronsummers
aaronsummers / file-get-contents-ssl.php
Created May 5, 2021 07:27
Fix file_get_contents() over ssl
<?php
/**
* File get contents fails without certificate on HTTPS
*
* https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-failed-to-enable-crypto#answer-40311146
*/
function file_get_contents_ssl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@aaronsummers
aaronsummers / wp-config.php
Last active June 30, 2021 23:05
WP-Config constants
<?php
/*
* limit post revisions to 3
*/
define( 'WP_POST_REVISIONS', 3 );
/*
* Debugging
*/
define( 'WP_DEBUG', true );
@aaronsummers
aaronsummers / responsive-image.html
Last active March 23, 2021 11:49
Responsive background image script
<!--
Each image is added to a new data attribute large, medium and small.
Add the image url followed by a space and then the width to apply the image.
Finally so the js can call the images add the responsive-bg class.
-->
<div class="elab_responsive-bg "
data-large="/images/hero-1440x360.jpg 1024"
data-medium="/images/hero-768x360.jpg 768"