Skip to content

Instantly share code, notes, and snippets.

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

David Browne wplit

💭
I may be slow to respond.
View GitHub Profile
@wplit
wplit / editor-styles.css
Created November 13, 2018 00:27
Change Gutenberg editor width
/* Main column width */
.wp-block {
max-width: 900px;
}
/* Width of "wide" blocks */
.wp-block[data-align="wide"] {
max-width: 1100px;
}
@wplit
wplit / snippet.php
Created December 5, 2018 23:00
Remove unused Oxygen's footer script markup
remove_action("wp_footer", "ct_footer_script_hook", 20);
@wplit
wplit / code-block.js
Last active December 7, 2018 00:14
add fade out effect to element on scroll
jQuery(function( $ ){
var element = $( ".element-class" );
function fade_element() {
window_scroll = $(this).scrollTop();
element.css({
'opacity' : 1-(window_scroll/300),
'transform' : "translate(0,"+ +(window_scroll/2) + "px)" });
});
@wplit
wplit / snippet.php
Last active January 16, 2019 22:08
Conditionally remove WP block editor (gutenberg) library CSS from front
add_action( 'wp_print_styles', 'lit_deregister_editor_styles', 100 );
/**
* Removes WP block editor styles
*/
function lit_deregister_editor_styles() {
if ( !is_singular('post') ) { // If isn't a single post, remove excess block libary CSS
wp_dequeue_style( 'wp-block-library' );
}
@wplit
wplit / snippet.php
Last active February 12, 2019 00:21
Fix Gutenberg messing up on staging sites (Request header field X-WP-Nonce is not allowed by Access-Control-Allow-Headers in preflight response.)
//Filter the WP Rest API URL.
add_filter('rest_url', function($url) {
$url = str_replace(home_url(), site_url(), $url);
return $url;
});
@wplit
wplit / snippet.php
Last active February 15, 2019 03:19
Remove default Gutenberg blocks from editor (because simplicity)
<?php
add_filter( 'allowed_block_types', 'lit_allow_these_block_types' );
function lit_allow_these_block_types( $allowed_blocks ) {
// Below is the array of blocks that ARE allowed, so comment out to remove from the editor.
return array(
'core/image',
'core/paragraph',
@wplit
wplit / snippet.php
Last active April 3, 2019 21:24
Remove default component CSS from Oxygen
// Remove default Oxygen.css
add_action( 'oxygen_enqueue_scripts', 'lit_dequeue_scripts' );
function lit_dequeue_scripts() {
wp_dequeue_style("oxygen");
}
@wplit
wplit / plugin.php
Last active April 16, 2019 16:10
Add backend styles for gutenberg, where style-editor.css is not available from theme. (like with Oxygen)
add_action( 'enqueue_block_editor_assets', 'lit_add_gutenberg_styles' );
/**
* Add backend styles for Gutenberg
*/
function lit_add_gutenberg_styles() {
wp_enqueue_style( 'custom-gutenberg-editor-styles', plugin_dir_url( __FILE__ ) . '/editor-styles.css');
}
@wplit
wplit / search.html
Last active May 9, 2019 10:46
search form for custom post type
<form role="search" method="get" id="searchform" class="searchform" action="https://yoursite.com/">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s">
<input type="hidden" value="product" name="post_type" />
<input type="submit" id="searchsubmit" value="Search">
</div>
</form>
@wplit
wplit / shortcode.php
Last active May 23, 2019 08:05
Shortcode to allow inserting reusable Gutenberg block into Oxygen template
add_shortcode('wp_oxy_reusable_block', 'lit_reusable_block_sc');
/**
* Add a shortcode to allow resuable blocks, that are created in WP editor, to be inserted in Oxygen templates using their IDs
*
* Sample usage: [wp_oxy_reusable_block id='2543']
*/
function lit_reusable_block_sc( $atts ) {
$attributes = shortcode_atts(
array(