Skip to content

Instantly share code, notes, and snippets.

View joshuadavidnelson's full-sized avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
@joshuadavidnelson
joshuadavidnelson / page-specific-sidebar.php
Last active August 29, 2015 14:01
Page Specific Sidebar in Genesis
<?php
/**
* Override the default sidebar in a Genesis Child Theme with the following code
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
add_action( 'genesis_setup', 'child_theme_setup' );
function child_theme_setup() {
@joshuadavidnelson
joshuadavidnelson / remove-page-template.php
Last active August 29, 2015 14:02
Remove Parent Theme Page Template
<?php
/**
* Remove Parent Theme Page Template
*
* @link http://wordpress.stackexchange.com/questions/13671/how-to-remove-a-parent-theme-page-template-from-a-child-theme#141654
**/
add_filter( 'theme_page_templates', 'jdn_remove_page_templates' );
function jdn_remove_page_templates( $templates ) {
unset( $templates['templates/page-template.php'] );
@joshuadavidnelson
joshuadavidnelson / taxonomy-archive-list-shortcode.php
Last active December 7, 2022 15:55
Shortcode to create a list or dropdown link to taxonomy archives
<?php
/**
* Shortcode to create a list or dropdown link to taxonomy archives
*
* @author Joshua David Nelson, josh@jdn.im
**/
function jdn_taxonomy_list( $atts ) {
$a = shortcode_atts( array(
'taxonomy' => '',
@joshuadavidnelson
joshuadavidnelson / unset-parent-page-templates.php
Last active August 29, 2015 14:03
Remove parent page templates from dropdown option in child theme pages
<?php
/**
* Removes parent theme page templates from the dropdown option on add new/edit page screen.
*
* Note that the path/to/ is from the parent theme directory, so if the page templates are in a subdirectory add that path,
* otherwise it can be written as 'page-template.php'
*
* @author Joshua David Nelson, josh@jdn.im
*/
@joshuadavidnelson
joshuadavidnelson / modify-metaboxes.php
Last active August 29, 2015 14:03
Modify medtaboxes
<?php
/**
* Registering meta boxes, based on these metaboxes:
* @link http://www.deluxeblogtips.com/meta-box/docs/define-meta-boxes
*/
// Add new metaboxes
add_action( 'admin_init', 'jdn_modify_metabox_fields', 1 );
/**
* Modify exist metaboxes to include a new field
* @author Joshua David Nelson, josh@joshuadnelson.com
@joshuadavidnelson
joshuadavidnelson / find-in-array.php
Last active July 10, 2016 21:46
Find a value in an array
<?php
/**
* Function to search for a metabox field and return the key
*
* @link http://stackoverflow.com/questions/8102221/php-multidimensional-array-searching-find-key-by-specific-value
*/
function jdn_find_in_array( $array, $needle, $term ) {
foreach( $array as $key => $value ) {
if ( $value[ $term ] === $needle )
@joshuadavidnelson
joshuadavidnelson / basic-usage.php
Last active July 27, 2018 11:32
Create custom theme features with theme feature support
<?php
/**
* Basic Theme Support usage. Add this to your functions.php file
*/
add_theme_support( 'custom-footer-text' );
/**
* Elsewhere in your theme...
*/
if( current_theme_supports( 'custom-footer-text' ) ) {
@joshuadavidnelson
joshuadavidnelson / force-ssl-all-pages.php
Last active January 12, 2018 06:23
Force SSL on all pages
<?php
/**
* Force SSL on all pages
*
* @author Joshua David Nelson, joshuadnelson.com
**/
add_action( 'template_redirect', 'jdn_force_ssl' );
function jdn_force_ssl() {
// force all pages to https://
<?php
/**
* Disable pingbacks
*
* Useful to secure your site from *potential* xmprpc DDoS attacks, but it does disable the pingback feature and could conflict with other plugins
*
* http://l.jdn.im/disable-pinkback
**/
add_filter( 'xmlrpc_methods', function( $methods ) {
@joshuadavidnelson
joshuadavidnelson / gravity-form-field-populate.php
Last active July 10, 2016 21:45
Edit fields on Gravity Form
<?php
/**
* Change the way a field is rendered in Gravity Forms.
*
* This example shows how you would dynamically create options for a select field.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
* @link
*/