Skip to content

Instantly share code, notes, and snippets.

@nickdavis
nickdavis / composer.json
Created July 29, 2022 10:22
composer.json starter
{
"name": "nickdavis/project-name",
"description": "",
"type": "project",
"license": "proprietary",
"prefer-stable": true,
"minimum-stability": "dev",
"repositories": [
{
"type": "composer",
@nickdavis
nickdavis / acf-fields-repeater.php
Created November 10, 2016 10:59
Advanced Custom Fields > Repeater field example (set programatically)
<?php
add_action( 'acf/init', 'nd_acf_add_local_field_groups' );
/**
* Add Advanced Custom Fields programatically (Repeater field).
*
* @link https://www.advancedcustomfields.com/resources/register-fields-via-php/
* @link https://support.advancedcustomfields.com/forums/topic/register-two-locations-via-php-doesnt-work/
* @link https://support.advancedcustomfields.com/forums/topic/adding-additional-layout-to-flexible_content-field-in-child-theme/
*
@nickdavis
nickdavis / wp-config.php
Last active June 29, 2022 11:04
Additional settings for wp-config.php (public version)
<?php
/**
* Debug.
*/
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );
/**
@nickdavis
nickdavis / functions.php
Created February 28, 2017 10:29
Add 'no-js' class to <html> tag in WordPress in order to work with Modernizr
<?php
add_filter( 'language_attributes', 'add_no_js_class_to_html_tag', 10, 2 );
/**
* Add 'no-js' class to <html> tag in order to work with Modernizr.
*
* (Modernizr will change class to 'js' if JavaScript is supported).
*
* @since 1.0.0
*
@nickdavis
nickdavis / yoast-seo-carbon-fields.js
Created February 21, 2019 21:21
Adding Carbon Fields to Yoast SEO content analysis
/**
* Adds specified Carbon Field to the Yoast SEO content analysis.
*
* @link https://return-true.com/adding-content-to-yoast-seo-analysis-using-yoastseojs/
* @link https://kb.yoast.com/kb/can-i-add-data-to-the-page-analysis/
* @link https://github.com/Yoast/YoastSEO.js/blob/master/README.md
* @link https://github.com/Yoast/YoastSEO.js/issues/181#issuecomment-163162489
*/
(function($) {
@nickdavis
nickdavis / template-iframe.php
Created October 21, 2014 19:28
Add a 'full width' iFrame (WordPress) page template using a custom field for the iFrame URL and including Genesis scripts (if set) in the header
<?php
// Template Name: iFrame
/**
* Get the URL for the iFrame from a custom field
*
* @link http://www.billerickson.net/advanced-custom-fields-frontend-dependency/
*/
$url = esc_url( get_post_meta( get_the_ID(), 'iframe', true ) );
@nickdavis
nickdavis / functions.php
Created January 29, 2017 16:32
Add Advanced Custom Fields PRO licence key programatically (via: https://gist.github.com/mattradford/6d5b8f3cd11ce1f62480#gistcomment-1933361)
<?php
class AutoActivator {
const ACTIVATION_KEY = 'youractivationkeyhere';
/**
* AutoActivator constructor.
* This will update the license field option on acf
* Works only on backend to not attack performance on frontend
*/
@nickdavis
nickdavis / ajax-call.php
Last active July 8, 2019 18:13
Cookies with a cached WordPress website (on WP Engine)
<?php
// Call Ajax
add_action( 'wp_ajax_ajax_action', 'esanctuary_sidebar_cookie'); // ajax for logged in users
add_action( 'wp_ajax_nopriv_ajax_action', 'esanctuary_sidebar_cookie' ); // ajax for not logged in users
<?php
add_filter( 'genesis_pre_get_option_content_archive_limit', __NAMESPACE__ . '\set_content_archive_limit', 11, 1 );
/**
* Forces the Genesis > Settings > Content Archives > Limit Content value to
* prevent an error with Events Calendar (v4.8.2) Archive pages in Genesis
* themes.
*/
function set_content_archive_limit() {
return 0;
@nickdavis
nickdavis / gist:10525079
Created April 12, 2014 08:41
.htaccess 301 redirect local WordPress dev site images folder to live website images folder (to save fllling up local drive with 1000's of unnecessary images)
#301 Redirect Local Images to Live
RedirectMatch 301 ^/wp-content/uploads/(.*) http://livewebsite.com/wp-content/uploads/$1