Skip to content

Instantly share code, notes, and snippets.

View johnmccole's full-sized avatar
💭
I may be slow to respond.

John McCole johnmccole

💭
I may be slow to respond.
  • Glasgow, Scotland
View GitHub Profile
@johnmccole
johnmccole / PlayerHealth.cs
Last active March 12, 2023 14:30
Place variables in string using $"{variableName}";
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using System;
public class PlayerHealth : MonoBehaviour
{
[Header("Health Attributes")]
@johnmccole
johnmccole / cpt-plugin.php
Last active March 10, 2023 20:10
Update namespace and CPT info as needed.
<?php
/**
* Plugin Name: Import Plugin
* Description: Wholegrain Starter plugin for developer test
* Version: 0.1
* Author: Wholegrain Digital
*/
namespace WGD;
add_action( 'wp_enqueue_scripts', 'enqueue_child_styles', 50 );
function enqueue_child_styles() {
wp_enqueue_style( 'child-theme-styles', get_stylesheet_directory_uri() . '/assets/css/child-styles.css', '', wp_get_theme()->get( 'Version' ) );
wp_enqueue_style( 'child-theme-fonts', 'https://use.typekit.net/drh6edk.css', '', wp_get_theme()->get( 'Version' ) );
}
<div class="container">
{!! App\show_last_updated() !!}
</div>
@johnmccole
johnmccole / config.json
Last active November 29, 2022 19:30
1. Update config.json to include a new gutenberg.scss file. 2. Update setup.php to enqueue the new file. 3. Edit guternberg.scss, copy in any essential styles from main.scss. 4. Build the project again.
"gutenberg": [
"./styles/gutenberg.scss"
],
if (function_exists('acf_add_options_sub_page')) {
acf_add_options_sub_page(array(
'page_title' => 'Actiss Options',
'menu_title' => 'Actiss Options',
'menu_slug' => 'actiss-options',
'capability' => 'manage_options',
'redirect' => false,
'position' => 1,
'parent_slug' => 'woocommerce', // add the options page to woocommerce menu
));
<?php
// original date format is YYYY-mm-dd
$date = $post->event_start_date;
// new format is dd-Month-YYYY
$newDate = date('d F Y', strtotime($post->event_start_date));
echo $newDate;
@johnmccole
johnmccole / function.php
Last active March 6, 2020 16:33
Example of custom shortcode function to output a Gravity Form form and accompanying html.
/* GUEST CHECKOUT SHORTCODE */
add_shortcode( 'cameron_guest_checkout', function( $atts, $content = null ) {
$atts = shortcode_atts( array(), $atts );
$output = '';
$current_user = wp_get_current_user();
if(is_user_logged_in()){
@johnmccole
johnmccole / custom-functions.php
Created February 19, 2020 14:51
Change sort order on archive pages, update with post type to only change specific post types.
add_action( 'pre_get_posts', 'my_change_sort_order');
function my_change_sort_order($query){
if(is_archive()):
//If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
//Set the order ASC or DESC
$query->set( 'order', 'ASC' );
//Set the orderby
$query->set( 'orderby', 'title' );
endif;
};
@php
$post_cats = get_the_category( get_the_ID() );
$cat_ids = array();
foreach($post_cats as $cat){
array_push($cat_ids, $cat->term_id);
}