Skip to content

Instantly share code, notes, and snippets.

View greghunt's full-sized avatar

Greg Hunt greghunt

View GitHub Profile
@greghunt
greghunt / save-upload
Created April 16, 2014 14:06
PHP Save Upload Script
function save_upload( $_FILES = false ) {
$photos = array();
if( $_FILES ) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
foreach( $_FILES as $name=>$photo ) {
$temp = explode(".", $photo["name"]);
@greghunt
greghunt / searchform.php
Created February 26, 2016 22:15
Wordpress HTML5 Bootstrap search form
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label for="searchField" class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></label>
<div class="input-group">
<input type="search" id="searchField" class="search-field"
placeholder="<?php echo esc_attr_x( 'Search the site for…', 'placeholder' ) ?>"
value="<?php echo get_search_query() ?>" name="s"
title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<?php echo esc_attr_x( 'Search', 'submit button' ) ?>
@greghunt
greghunt / image-brightness.scss
Created March 1, 2018 23:12
Control Background Brightness with CSS
.image {
width: 200px;
height: 200px;
background: no-repeat center center;
background-image: url(https://images.unsplash.com/photo-1464823063530-08f10ed1a2dd?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=f0976bd6d336e2aeb5e06dbc366515ea&auto=format&fit=crop&w=1650&q=80);
background-size: cover;
position: relative;
&:after {
content: "";
display: block;
@greghunt
greghunt / breakout-container.scss
Created March 11, 2018 19:41
Break out of container for full width section that conserves page flow.
@mixin breakout() {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
@greghunt
greghunt / css-color-names.csv
Last active March 11, 2018 19:42
CSS Color Names Separated by comma
AliceBlue AntiqueWhite Aqua Aquamarine Azure Beige Bisque Black BlanchedAlmond Blue BlueViolet Brown BurlyWood CadetBlue Chartreuse Chocolate Coral CornflowerBlue Cornsilk Crimson Cyan DarkBlue DarkCyan DarkGoldenRod DarkGray DarkGrey DarkGreen DarkKhaki DarkMagenta DarkOliveGreen Darkorange DarkOrchid DarkRed DarkSalmon DarkSeaGreen DarkSlateBlue DarkSlateGray DarkSlateGrey DarkTurquoise DeepPink DeepSkyBlue DimGray DimGrey DodgerBlue FireBrick FloralWhite ForestGreen Fuchsia Gainsboro GhostWhite Gold GoldenRod Gray Grey Green GreenYellow HoneyDew HotPink IndianRed Indigo Ivory Khaki Lavender LavenderBlush LawnGreen LemonChiffon LightBlue LightCoral LightCyan LightGoldenRodYellow LightGray LightGrey LightGreen LightPink LightSalmon LightSeaGreen LightSkyBlue LightSlateGray LightSlateGrey LightSteelBlue LightYellow Lime LimeGreen Linen Magenta Maroon MediumAquaMarine MediumBlue MediumOrchid MediumPurple MediumSeaGreen MediumSlateBlue MediumSpringGreen MediumTurquoise MediumVioletRed MidnightBlue MintCream Mis
@greghunt
greghunt / autosubmit.js
Created March 12, 2018 14:40
Auto-submit a form
$("[data-autosubmit]").on('change', function(){
$(this).parents("form").submit();
});
@greghunt
greghunt / get-filtering.php
Last active March 12, 2018 14:43
Add GET based filtering of WordPress queries.
<?php
/**
* Allow filtering of index/archives by GET
* Example) Adding ?sort=-date will sort posts descending by date.
* Possible Values: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
*/
add_action('pre_get_posts', function ($query) {
if( $query->is_main_query() ) {
$sort = "relevance";
$order = "DESC";
@greghunt
greghunt / wp-non-orphaned-titles.php
Last active March 13, 2018 16:08
No WP orphans
<?php
function no_orphans( $title ) {
global $post;
if( $title == $post->post_title ){
//Take apart
$title_words = explode(' ', $title);
$tile_without_last_word = array_slice($title_words, 0, -1);
$last_word = array_slice($title_words, -1, 1);
@greghunt
greghunt / toggle-class.js
Last active April 1, 2018 04:51
Toggle Class with jQuery
/*
* <button data-toggle-class="#targetDiv:some-class">Toggle this Class on the Element</button>
*/
$("[data-toggle-class]").on('click', function(e){
e.preventDefault();
const config = $(this).data('toggle-class').split(':');
const $target = $(config[0]);
const className = config[1];
@greghunt
greghunt / Shortcodes.php
Created October 10, 2018 12:23
Simple class for organizing and registering your WordPress shortcodes.
<?php
namespace App;
class Shortcodes {
protected $shortcodes = [];
public function __construct()
{