Skip to content

Instantly share code, notes, and snippets.

View chriswinch's full-sized avatar

Chris Winch chriswinch

View GitHub Profile
function ajax_setup_scripts() {
// Register and Enqueue Script
wp_register_script('afp_script', get_template_directory_uri() . '/js/scripts.js', false, null, false);
wp_enqueue_script('afp_script');
wp_localize_script( 'afp_script', 'afp_vars', array(
'afp_nonce' => wp_create_nonce( 'afp_nonce' ),
'afp_ajax_url' => admin_url( 'admin-ajax.php' ),
)
);
@chriswinch
chriswinch / functions.php
Last active March 21, 2019 21:40
Custom Wordpress Nav Walker - Add your own classnames to WP_Nav_Menu
// Updated the Walker_Nav_Menu class to accept an array of classnames via argument
// Comments below show what has been changed / updated
// Original Walker_Nav_Menu copied from here: https://core.trac.wordpress.org/browser/tags/4.5.3/src//wp-includes/nav-menu-template.php#L0
<?php
class Nav_Walker extends Walker_Nav_Menu {
// Setup empty $data array
// Can be used to store any other data
private $data = [];
@chriswinch
chriswinch / functions.php
Last active October 7, 2016 06:57
ACF - Combine the_field & the_sub_field into one function for better modularity.
<?php
function the_acf_field($acf) {
$field = get_field($acf);
if(!$field) {
$field = get_sub_field($acf);
}
echo $field;
@chriswinch
chriswinch / index.html
Last active May 3, 2019 11:14
Google Web Font Loader with LocalStorage
<script>
if (window.localStorage && window.localStorage._gf_cache) {
document.documentElement.classList.add('wf-active');
var script = document.createElement('script');
script.innerHTML = localStorage._gf_cache;
document.head.appendChild(script);
}
window._gfonload = function () {
var req = new XMLHttpRequest()
req.addEventListener("load", function () {