Skip to content

Instantly share code, notes, and snippets.

View joshuadavidnelson's full-sized avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
@joshuadavidnelson
joshuadavidnelson / has-gform.php
Created October 28, 2015 06:45
Check if the page has a gravity form
<?php
/**
* Check if the page has a gravity form.
*
* @since 1.0.0
*
* @param int $id Post or page id, default to false.
*
* @return boolean
*/
<?php
if ( ! function_exists( 'plugin_do_action' ) ) {
function plugin_do_action( $filter, $modifiers ) {
if ( ! is_array( $modifiers ) ) {
$modifiers = array( $modifiers );
}
// add an empty modifier so the base filter will be applied as well
array_unshift( $modifiers, '' );
@joshuadavidnelson
joshuadavidnelson / jquery-bootstrap-datepicker.css
Created October 5, 2015 05:38 — forked from miwahall/jquery-bootstrap-datepicker.css
jQuery UI Datepicker Bootstrap 3 Style
.ui-datepicker {
background-color: #fff;
border: 1px solid #66AFE9;
border-radius: 4px;
box-shadow: 0 0 8px rgba(102,175,233,.6);
display: none;
margin-top: 4px;
padding: 10px;
width: 240px;
}
@joshuadavidnelson
joshuadavidnelson / line-on-side-headers.js
Created September 5, 2015 05:24
Add line-on-side headers. Fallback for non-javascript browsers is no lines.
jQuery(function( $ ){
// Sets the horizontal location of the lines
$(document).ready(function () {
var entryHeaderWidth = $('.entry-title').width();
var titleWidth = $('.entry-title .title').width();
$('.entry-title span.before').css("right", entryHeaderWidth/2+titleWidth/2 );
$('.entry-title span.after').css("left", entryHeaderWidth/2+titleWidth/2 );
});
});
@joshuadavidnelson
joshuadavidnelson / functions.php
Last active August 9, 2016 20:20
Add a parallax image behind a page entry header in Genesis - pure css solution. (You'll need to style your image to be tall enough to match the webpage header, so it is behind the main page header on scroll)
<?php
/**
* Add a parallax image behind a page entry header in genesis.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
// Parallax Image
add_action( 'genesis_header', 'parallax_image', 15 );
/**
@joshuadavidnelson
joshuadavidnelson / correct-method.php
Last active January 15, 2016 18:52
Deprecated Widget Constructors
<?php
/**
* Correct method for WordPress 4.3
* @see https://make.wordpress.org/core/2015/07/02/deprecating-php4-style-constructors-in-wordpress-4-3/
* @see http://codex.wordpress.org/Widgets_API
*/
class My_Widget extends WP_Widget {
/**
* Sets up the widgets name etc
@joshuadavidnelson
joshuadavidnelson / posts-exist.php
Created August 14, 2015 05:16
Check is a post type exists in a specific status
<?php
/**
* Check if posts exist in a post type.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*
* @param string $post_type The post type slug (required).
* @param
*/
function posts_exist( $post_type, $post_status = 'publish' ) {
@joshuadavidnelson
joshuadavidnelson / remove-feeds.php
Last active May 26, 2017 23:33 — forked from chrisguitarguy/remove-feeds.php
Remove all feeds from WordPress
<?php
add_action( 'wp_head', 'remove_feeds_from_wp_head', 1 );
/**
* Remove feed links from wp_head
*/
function remove_feeds_from_wp_head() {
// Remove feed links
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
@joshuadavidnelson
joshuadavidnelson / add-metabox-to-genesis-cpt-archive-settings.php
Last active August 31, 2019 21:11
Adding Metaboxes to Genesis CPT Archive Settings, walkthrough publishing August 7th at https://joshuadnelson.com/blog
<?php
/**
* Add custom metabox to Genesis CPT Archive Settings.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*
* @link https://joshuadnelson.com/adding-metaboxes-to-genesis-cpt-archive-settings
*/
class JDN_Genesis_CPT_Archive_Settings {
@joshuadavidnelson
joshuadavidnelson / force-draft.php
Last active August 29, 2015 14:26
Force a post to draft if specific meta is invalid, in this case the start and end date/time.
<?php
/**
* For a post to draft if specific meta is invalid, in this case the start and end date/time.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
add_action( 'updated_post_meta', 'jdn_force_draft', 10, 2 );
function jdn_force_draft( $meta_id, $post_id ) {
if( get_post_type( $post_id ) == 'events' ) {
$start = get_post_meta( $post_id, 'event_start', true );