Skip to content

Instantly share code, notes, and snippets.

View bmdinteractive's full-sized avatar

Brian Douglas bmdinteractive

View GitHub Profile
@bmdinteractive
bmdinteractive / custom-search-acf-wordpress.php
Last active May 6, 2016 10:14 — forked from jserrao/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request. I updated this original script with better documentation and XSS / SQL injection support.
/*
##############################
########### Search ###########
##############################
*/
/**
*
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
@bmdinteractive
bmdinteractive / acf-ninja-form-dropdown.php
Created August 6, 2017 22:41
Load All Ninja Forms into Advance Custom Fields Dropdown
function acf_load_ninja_form_field_choices( $field ) {
// reset choices
$field['choices'] = array();
$ninja_forms = Ninja_Forms()->form()->get_forms();
foreach($ninja_forms as $nf):
$value = '[ninja_forms id='.$nf->get_id().']';
$nf_settings = $nf->get_settings();
$label = $nf_settings['title'];
@bmdinteractive
bmdinteractive / sort_taxonomy.php
Created August 7, 2017 14:10
Sort taxonomy by custom field 'display_order'
$terms = get_terms( 'taxonomy_name', array(
'hide_empty' => true,
) );
$terms_sorted = array( );
foreach ( $terms as $term ) {
$single_term = get_term($term);
$display_order = get_field( 'display_order', $term );
$terms_sorted[$display_order] = $term;
}
@bmdinteractive
bmdinteractive / add-page-slug-to-body.php
Created August 7, 2017 15:29
Add page slug to body class
//Page Slug Body Class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );
function shortcode_name(){
// Shortcode Description
ob_start(); ?>
<?php
wp_reset_query();
return ob_get_clean();
}
add_shortcode('shortcode_name', 'shortcode_name' );
@bmdinteractive
bmdinteractive / strip_title_from_breadcrumb_output.php
Created November 20, 2017 19:30
Removes the current page title from Yoast breadcrumbs
function strip_title_from_breadcrumb_output( $output ){
$output = str_replace( get_the_title(), '', $output );
return $output;
}
add_filter( 'wpseo_breadcrumb_output', 'strip_title_from_breadcrumb_output' );
@bmdinteractive
bmdinteractive / wp_add_type_slug_body_class.php
Created November 20, 2017 19:30
Adds the post type and page slug to body class
function add_type_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_type_slug_body_class' );
@bmdinteractive
bmdinteractive / smooth-scroll.js
Last active July 31, 2018 16:00
Smooth Scrolling for Internal Links
(function ($) {
$('a[href*="#"]')
// Remove links that don't actually link to anything
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
// On-page links
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
&&
@bmdinteractive
bmdinteractive / wp-permissions.sh
Created August 1, 2018 20:06
WP Permissions Fixer
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro
#
WP_OWNER=www-data # &lt;-- wordpress owner
WP_GROUP=www-data # &lt;-- wordpress group
WP_ROOT=/var/www/html # &lt;-- wordpress root directory
@bmdinteractive
bmdinteractive / add-svg.php
Created September 3, 2018 16:42
Add SVG to allowable mime types in WordPress
function mime_types($mimes) {
// Enable SVG
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'mime_types' );