Skip to content

Instantly share code, notes, and snippets.

View johnregan3's full-sized avatar

John Regan johnregan3

View GitHub Profile
@johnregan3
johnregan3 / dynamically-generated-settings.php
Last active May 25, 2023 07:35
A method for dynamically generating Settings Fields in WordPress through the use of an anonymous function assigned to a variable variable. This could be expanded to generate different input types (hidden, text, textarea, and maybe a select), and to dynamically generate Setting Sections and Section Callbacks.
<?php
/*
* Dynamically Generated Checkboxes in a WordPress Settings Page
*
* This file is fully functional and ready to be used in a plugin or theme to generate this Settings Page
*
*/
Class Pizza_Shop {
@johnregan3
johnregan3 / cpt_in_wp_submenu.php
Last active December 3, 2022 07:32
Add Custom Post Type to WordPress Plugin Submenu (Hack)
<?php
/*
Plugin Name: Nerfherder Plugin
Plugin URI: https://gist.github.com/johnregan3/6133389
Description: Demonstration of how to add Custom Post Types to Submenu Items
Author: John Regan
Author URI: http://johnregan3.com
Version: 1.0
*/
@johnregan3
johnregan3 / wp-amp-tutorial-strip-shortcodes.php
Last active October 20, 2021 17:43
Strip out all Shortcodes for a WordPress AMP template.
<?php
/**
* Strip out all shortcode content.
*
* This is a quick and dirty way
* to ensure no shortcodes introduce
* invalid markup into an amp template.
*
* @param string $content WP Post content.
*
@johnregan3
johnregan3 / cloudSettings
Last active July 9, 2020 11:38
VSCode settings
{"lastUpload":"2020-07-09T11:37:59.707Z","extensionVersion":"v3.4.3"}
@johnregan3
johnregan3 / wp-amp-tutorial-menu.php
Last active December 31, 2019 03:01
Creating a Menu using amp-sidebar in WordPress
<?php
/**
* Render the Primary Nav Menu
*
* Uses amp-sidebar to handle
* slideout animation.
*
* Be sure to include the amp-sidebar component script.
* Also, rememeber that the amp-sidebar element must be
* a direct child of the <body>.
@johnregan3
johnregan3 / oop-plugin-basic.php
Last active December 27, 2019 00:42
Basic Demonstration of Using OOP in a WordPress Plugin
/*
* Plugin Header...
*
* Note: This particular block of code won't actually run because it doesn't have
* the details of the register_post_type and register_taxonomy functions filled in.
*/
class JR3_Books {
/**
@johnregan3
johnregan3 / wp-amp-tutorial-filter-shortcode-podcast.php
Last active December 25, 2019 13:06
Filtering WP Shortcodes to comply with AMP standards.
<?php
/**
* Hijack a hypothetical [podcast] custom shortcode for AMP.
*
* Replaces [podcast] output with amp-audio.
*
* Be sure you've added the amp-audio component script to the template.
*
* @filter the_content
*
@johnregan3
johnregan3 / gutenberg-custom-editor-styles.php
Last active April 16, 2019 16:08
Gutenberg Custom Editor Styles - PHP
<?php
/**
* Enqueue the Gutenberg editor stylesheet.
*
* Put this in your functions.php.
*
* @action enqueue_block_editor_assets
*/
function jr3_enqueue_gutenberg() {
// Make sure you link this to your actual file.
@johnregan3
johnregan3 / wp-amp-tutorial-primary-nav.php
Last active February 13, 2019 16:39
Adding a Primary Navigation Menu to an AMP WordPress Theme
<?php
/**
* Register the amp-sidebar component script with WP AMP.
*
* This goes in your amp.php
*/
function jr3_amp_sidebar_component_script( $data ) {
$data['amp_component_scripts']['amp-sidebar'] = 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js';
return $data;
}
@johnregan3
johnregan3 / wordpress-transients-tutorial-02.php
Last active December 26, 2018 15:10
WordPress Transients Tutorial, Part 2
<?php
/**
* Get Books posts.
*
* This is from a tutorial found here:
* @link https://johnregan3.wordpress.com/how-to-improve-wordpress-load-times-using-transients
*
* @since 1.0.0
*
* @param array $genre_array An array of genre slugs.