Skip to content

Instantly share code, notes, and snippets.

@solepixel
solepixel / acf-set-field-name.php
Created Jun 8, 2016
Differentiate Settings Page fields when using the same field groups. Requires "menu_slug" prefixed with something common and identifiable, in this case the Post Type of the Archive as well as a common naming convention, in this example it uses "-archive-settings".
View acf-set-field-name.php
<?php
add_filter( 'acf/load_field', 'mytheme_set_field_name' );
function mytheme_set_field_name( $field ){
if( is_admin() ){
$screen = get_current_screen();
if( $screen->id == 'acf-field-group' )
return $field;
@solepixel
solepixel / algolia-2.php
Last active Oct 27, 2020
Custom parameters for Algolia search in WordPress
View algolia-2.php
<?php
add_filter( 'algolia_terms_index_settings', '__return_empty_array' );
add_filter( 'algolia_users_index_settings', '__return_empty_array' );
add_filter( 'algolia_posts_listing_index_settings', 'mytheme_algolia_listing_settings' );
function mytheme_algolia_listing_settings( $settings ){
$numeric_fields = array_keys( mytheme_algolia_faceted_fields( array( 'int', 'float' ) ) );
$string_fields = array_keys( mytheme_algolia_faceted_fields( 'string' ) );
@solepixel
solepixel / batch-download-images.sh
Created Mar 2, 2017
Use wget to batch download a list of image URLs
View batch-download-images.sh
wget -i image-list.txt --force-directories
@solepixel
solepixel / .htaccess
Last active Jul 1, 2020
This htaccess snippet (lines 6-13) will pull any missing images from another URL. Helpful when developing locally or on a staging site where media is present on production but is too much to migrate to staging or locally.
View .htaccess
# BEGIN Media from Live Site
<IfModule mod_rewrite.c>
RewriteEngine On
# Use uploads directory from live site
RewriteBase /wp-content/uploads/
RewriteCond %{HTTP_HOST} !^www\.livedomain\.com
RewriteCond %{HTTP_HOST} !^livedomain\.com
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
@solepixel
solepixel / movie-calendar.md
Last active Jun 16, 2020
365 Days of Movies - A work in progress
View movie-calendar.md

365 Days of Movies

January 1 - Rocky

January 6 - Sherlock Holmes

January 11 - Goodfellas

February 2 - Groundhog Day

@solepixel
solepixel / gf-custom-validation.php
Last active Feb 25, 2020
Fixes Gravity Forms Custom Validation Message
View gf-custom-validation.php
<?php
add_filter( 'gform_field_validation', 'mytheme_fix_custom_validation', 10, 4 );
/**
* Fixes Gravity Forms Custom validation message.
*
* @link https://docs.gravityforms.com/gform_field_validation/
*
* @param array $result The result array.
@solepixel
solepixel / folder-structure.txt
Last active Jan 30, 2020
This is my go-to package.json and gulpfile.js templates
View folder-structure.txt
PROJECTNAME/
| bin -- Can be excluded from project distribution.
| images/ -- Images added here will be optimized.
| sass/
| blocks/
| BLOCKNAME/ -- SCSS files for BLOCKNAME.
| BLOCKNAME.scss -- Repeat for all blocks needed.
| PROJECTNAME.scss
| PROJECTNAME-admin.scss
| editor-styles.scss -- Admin editor specific styles.
@solepixel
solepixel / activate-plugin.php
Created Aug 26, 2016
Originally design to activate Andrew Norcross's Airplane Mode plugin (https://github.com/norcross/airplane-mode), this little script will allow you to activate a plugin when the WordPress admin plugin screen cannot be loaded, for whatever reason.
View activate-plugin.php
<?php
/**
* This file will activate the Airplane Mode plugin if not already activated. This is helpful when you do not have internet connection and you're unable to reach the WP Admin Plugins page to activate the plugin.
*/
// get WP bootstrap
define('WP_USE_THEMES', false);
require(__DIR__ . '/wp/wp-blog-header.php');
@solepixel
solepixel / formatted-args.txt
Created Sep 7, 2016
ElasticPress arguments
View formatted-args.txt
Array
(
[from] => 0
[size] => 54
[sort] => Array
(
[0] => Array
(
[meta_value_num] => Array
(
@solepixel
solepixel / wp-config.php
Created Dec 20, 2018
Enable WP_DEBUG on production sites - Only do this temporarily to find problems. Disable and delete wp-content/debug.log when you've resolved your issue.
View wp-config.php
<?php
// ^^ Other config settings such as database credentials. ^^
/**
* WordPress debugging mode.
*
* For information on other constants that can be used for debugging,
* visit the Codex.
*