Skip to content

Instantly share code, notes, and snippets.

View theJasonJones's full-sized avatar

Jason Jones theJasonJones

  • Edward Jones
  • St. Louis, MO
View GitHub Profile
import React, { useState } from "react";
import "./App.css";
import Form from "./Form";
const App = () => {
const [todos, setTodos] = useState([]);
const toggleComplete = i =>
setTodos(todos.map(
(todo, k) =>
@theJasonJones
theJasonJones / gutenberg-color-pallete-theme.php
Last active February 28, 2018 17:32 — forked from zgordon/gutenberg-color-pallete-theme.php
Add theme support and set a color palette for all blocks
<?php
function mytheme_setup_theme_supported_features() {
add_theme_support( 'editor-color-palette',
'#556270',
'#4ECDC4',
'#C7F464',
'#FF6B6B',
'#C44D58'
);
@theJasonJones
theJasonJones / Twitter.md
Last active March 30, 2017 16:25
Twitter API Access in PHP

Twitter API Timeline Retrieval

@theJasonJones
theJasonJones / README.md
Last active July 24, 2024 18:02
Auto Populate Wordpress ACF Repeater values

Add default values to ACF Repeater Fields

I came across this solution when I had about a ton of posts (200+) with values in various PDFs. I didn't want to have to spend time filling out the same values over and over again.

Walkthrough

This case is pretty straight forward; I have one repeater field field_123a56b7cb890 that has a text fields inside it (field_588a24c3cb782). I haven't tried any other types like post objects or radio buttons, but I'm sure it can be done.

Step 1. Hook into acf/load_value on your repeater field. You can use type/key/name as desired here.

@theJasonJones
theJasonJones / addRemove.js
Last active February 7, 2017 19:20
Header shrink with custom JS add/remove
//Add listener for when the user scrolls more than 64px
function init() {
window.addEventListener('scroll', function(e){
var distanceY = window.pageYOffset || document.documentElement.scrollTop, //get offset from top
distanceX = window.innerWidth, //get window width
shrinkOn = 64,
header = document.querySelector(".header");
if( distanceX > 992 ){ // Optional: Unfixes the menu at a certain break
if (distanceY > shrinkOn) {
@theJasonJones
theJasonJones / functions.php
Created December 2, 2016 21:21
f you want to set the main events page title to appear similar to the titles listed on the rest of the site you can use this function.
add_filter('wp_title', 'normal_tribe_events_title');
function normal_tribe_events_title($title) {
if( get_post_type() == 'tribe_events' ){
$title = get_bloginfo('name');
return $title;
}
}
var decodeEntities = (function() {
// this prevents any overhead from creating the object each time
var element = document.createElement('div');
function decodeHTMLEntities (str) {
if(str && typeof str === 'string') {
// strip script/html tags
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
element.innerHTML = str;
@theJasonJones
theJasonJones / index.php
Created December 1, 2016 16:45
Google Maps Direction API with Custom Map
<div>
<div id="map-canvas"></div>
</div>
<script>
function initMap() {
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});
var map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 10,
@theJasonJones
theJasonJones / functions.php
Last active November 30, 2016 21:20
Add async or defer to a WordPress script
//Enqueue JS like we normally do.
function add_test_js_files(){
wp_enqueue_script('script1', '//script1.js?cid=6asdfsdf');
wp_enqueue_script('script2', '//script2.js?cid=a213423423');
}
add_action('wp_enqueue_scripts','add_test_js_files');
function add_async_attribute($tag, $handle) {
@theJasonJones
theJasonJones / functions.php
Last active November 11, 2016 17:17
Forces a featured image to set and displays error if one isn't set.
add_action('save_post', 'pk_require_post_thumbnail');
add_action('admin_notices', 'pk_post_thumbnail_error');
function pk_require_post_thumbnail($post_id) {
// change to any custom post type
if(get_post_type($post_id) != 'post')
return;
if ( !has_post_thumbnail( $post_id ) ) {