Skip to content

Instantly share code, notes, and snippets.

@bradpotter
bradpotter / functions.php
Last active June 1, 2021 15:12
Place a reusable Gutenberg block via a Genesis hook. (Where 956 is the Post ID of your reusable block)
add_action( 'genesis_before_footer', 'my_custom_query' );
function my_custom_query() {
$post_id = 956;
$queried_post = get_post($post_id);
echo $queried_post->post_content;
}
@bradpotter
bradpotter / functions.php
Created May 25, 2019 01:32 — forked from seothemes/functions.php
Dynamic CSS in WordPress
<?php
/**
* Load dynamic CSS stylesheet in WordPress. There are 4 steps:
*
* 1. Enqueue dynamic stylesheet on front end or add inline CSS if in Customizer.
* 2. Get the dynamic CSS with AJAX calls.
* 3. Generate CSS using PHP variables.
* 4. Minify CSS after before loading.
*/
@bradpotter
bradpotter / verse-cpt.php
Last active May 23, 2019 21:26
First run at Bible Verse CPT
add_action( 'init', 'book_create_custom_taxonomy' );
function book_create_custom_taxonomy() {
// Book
$book = array(
'name' => _x( 'Book', 'taxonomy general name' ),
'singular_name' => _x( 'Book', 'taxonomy singular name' ),
'menu_name' => __( 'Book' ),
'all_items' => __( 'All Books' ),
'parent_item' => __( 'Parent Book' ),
@bradpotter
bradpotter / onboarding.php
Created December 20, 2018 21:34
Modify onboarding.php to include additional pages
return array(
'dependencies' => array(
'plugins' => array(
array(
'name' => __( 'Atomic Blocks', 'genesis-sample' ),
'slug' => 'atomic-blocks/atomicblocks.php',
),
),
),
'content' => array(
@bradpotter
bradpotter / add-editor-layout-classes.js
Created April 7, 2019 07:26 — forked from nickcernis/add-editor-layout-classes.js
Add Genesis layout class to Gutenberg editor pages (admin)
// Add genesis layout classes to the Block Editor.
// File lives in the theme's /js/ folder.
wp.domReady(function () {
yourTheme.updateLayoutClass();
var layouts = document.querySelector(".genesis-layout-selector");
layouts.addEventListener("input", function (e) {
yourTheme.updateLayoutClass();
});
});
@bradpotter
bradpotter / functions.php
Created April 7, 2019 07:26 — forked from nickcernis/functions.php
Wrap Custom HTML WordPress blocks in a div wrapper
<?php
add_filter( 'render_block', 'custom_wrap_html_block_output', 10, 2 );
/**
* Wrap output of HTML blocks.
*
* @param string $block_content Original block content.
* @param array $block Block info.
* @return string The block content with a wrapper.
*/
@bradpotter
bradpotter / class-custom-featured-post.php
Created March 30, 2019 00:17 — forked from srikat/class-custom-featured-post.php
Custom Featured Posts Widget plugin: Skeleton for amending the output of the Genesis Featured Posts widget. https://sridharkatakam.com/custom-featured-post-widget-plugin/
<?php
/**
* Plugin Name
*
* @package Custom_Featured_Post_Widget
* @author Gary Jones
* @license GPL-2.0+
* @link http://gamajo.com/
* @copyright 2013 Gary Jones, Gamajo Tech
*/
@bradpotter
bradpotter / functions.php
Last active December 15, 2017 23:06
Modify post type for Gutenberg
function modify_post_type() {
//new args
$args = array(
'public' => true,
'label' => 'Posts',
'show_in_rest' => true,
'template' => array(
array( 'core/cover-image' ),
array( 'core/image' ),
@bradpotter
bradpotter / responsive-menu-header-pri-sec.js
Last active October 31, 2017 22:20
Combine Header, Primary and Secondary Menu into one Responsive Menu
/* Make sure your Menus are named Header Navigation, Primary Navigation and Secondary Navigation in Appearance > Menus */
(function( window, $, undefined ) {
'use strict';
$('.nav-primary').before('<button class="menu-toggle" role="button" aria-pressed="false"></button>'); // Add toggles to menus
$('nav .sub-menu').before('<button class="sub-menu-toggle" role="button" aria-pressed="false"></button>'); // Add toggles to sub menus
// Show/hide the navigation
$('.menu-toggle, .sub-menu-toggle').click(function() {
@bradpotter
bradpotter / functions.php
Last active July 18, 2017 08:26
How to Add “Top” and “Footer” Menus to Genesis
// Register and Hook Top Navigation Menu
add_action('genesis_before_header', 'sample_before_header_menu', 10);
function sample_before_header_menu() {
register_nav_menu( 'top', 'Top Navigation Menu' );
genesis_nav_menu( array(
'theme_location' => 'top',
'menu_class' => 'menu genesis-nav-menu menu-top',
) );