Skip to content

Instantly share code, notes, and snippets.

View AustinGil's full-sized avatar

Austin Gil AustinGil

View GitHub Profile
<form method="POST" action="https://api.pizza.com">
<label for="name">Name</label>
<input id="name" name="name" />
<label for="email">Email</label>
<input id="email" name="email" type="email" />
<fieldset>
<legend>Pizza toppings</legend>
<input id="cheese" name="toppings" value="cheese" type="checkbox" />
@AustinGil
AustinGil / weighted-ratio.js
Last active August 6, 2019 18:41
Get the conversion ratio for a non-linear, weighted return
/**
* A function that converts a number to another based on a weighted conversion function.
* @function applyConversion
* @param {number} responseCode
* @return {number} responseMessage
*/
/**
* Creates a function that applies the weighted conversion between two ranges.
* @param { number } oldMin The old range minimum value
@AustinGil
AustinGil / default.conf
Created August 8, 2018 15:35
NGiNX Configuration for Vue-Router in HTML5 Mode
server {
listen 80 default_server;
listen [::]:80 default_server;
root /your/root/path;
index index.html;
server_name you.server.com;
@AustinGil
AustinGil / template.php
Last active August 29, 2017 17:51
Loop through posts that are missing meta data, and add some default value
<?php
/**
* Template Name: Full Width
*
* Gets all posts that are missing default meta value, and gives them a default meta value.
* Add this file to your theme then add a page with this template.
*
* IMPORTANT:
* Visit that page and keep refreshing until you see no more posts left.
* Each page load adds the new post meta, so the loop count drops by the posts_per_page count each time.
@AustinGil
AustinGil / scripts.js
Created April 17, 2017 19:42
Create social sharing buttons in WordPress that open popup for sharing
/** SOCIAL MEDIA SHARES */
var shareBtns = document.querySelectorAll('.social-share-btns a');
shareBtns.forEach( function(btn) {
btn.addEventListener('click', function(e) {
e.preventDefault();
var width = 575, height = 400,
left = (document.documentElement.clientWidth / 2 - width / 2),
top = (document.documentElement.clientHeight - height) / 2,
@AustinGil
AustinGil / functions.php
Last active November 23, 2017 23:34
AJAX load more posts
function assets() {
// enqueue your script
wp_enqueue_script('handle', get_template_directory_uri() . '/path/to/main.js', ['jquery'], '$ver', true);
// localize script
wp_localize_script('handle', 'custom_ajaxify', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
add_action('wp_enqueue_scripts', 'assets', 100);
/**
* AJAX load template part
@AustinGil
AustinGil / functions.php
Created April 4, 2017 18:50
Loading more posts with AJAX
/**
* AJAX load template part
*/
function prefix_ajax_load_template_part() {
echo get_template_part('templates/ajax-template-part');
die();
}
add_action('wp_ajax_nopriv_ajax_load_initiatives', 'prefix_ajax_load_template_part');
add_action('wp_ajax_ajax_load_initiatives', 'prefix_ajax_load_template_part');
@AustinGil
AustinGil / functions.php
Last active November 15, 2017 14:56
Function for better truncating text in WordPress. Great for custom excerpts.
/**
* Takes a string and returns a truncated version. Also strips out shortcodes
*
* @param string $text String to truncate
* @param integer $length Character count limit for truncation
* @param string $append Appended to the end of the string if character count exceeds limit
* @return string Truncated string
*/
function truncate_text( $text='', $length = 50, $append = '...') {
$new_text = preg_replace(" ([.*?])",'',$text);
@AustinGil
AustinGil / new-wp.sh
Last active September 11, 2024 19:08
Bash script to install and set up WordPress on new cPanel account in WHM
#/bin/bash
# Script for automating new account setups with WordPress installed
echo Lets setup a new WordPress dev site!
# Get user input
# Us RegEx to check for valid domain
read -p 'Enter the domain name: ' domain
result=`echo $domain | grep -P '(?=^.{1,254}$)(^(?>(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)'`
if [[ -z "$result" ]]
@AustinGil
AustinGil / functions.php
Last active September 14, 2020 11:56
JSON-LD for WordPress posts
/**
* Remove hentry from post_class
* This is important to not get schema errors
*/
function visceral_remove_hentry_class( $classes ) {
$classes = array_diff( $classes, array( 'hentry' ) );
return $classes;
}
add_filter( 'post_class', 'visceral_remove_hentry_class' );