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 / style.css
Last active February 14, 2022 07:23
Allow tabbing across the sub menu items in Oxygen Menu (for keyboard user)
/* Allows focus on sub menu items by tabbing menu
------------------------------------------------ */
.oxy-nav-menu:not(.oxy-nav-menu-open) .menu-item .sub-menu {
right: 5000px;
visibility: visible;
}
.oxy-nav-menu:not(.oxy-nav-menu-open).menu-item .sub-menu .sub-menu {
right: auto;
@wplit
wplit / tab-element.js
Last active December 14, 2022 09:57
Allow hash links to open tabs in Oxygen (read comments for instructions)
var hash = window.location.hash.substr(1);
if (hash == '%%ELEMENT_ID%%') {
setTimeout(function(){
jQuery([document.documentElement, document.body]).animate({
scrollTop: jQuery('#' + '%%ELEMENT_ID%%').offset().top - 100
}, 1000);
jQuery('#' + '%%ELEMENT_ID%%').trigger('click');
@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 / 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(
@wplit
wplit / snippet.php
Last active June 20, 2019 04:51
Adds quick link to resign shortcodes in admin bar, useful when moving between staging - dev areas when using Oxygen
add_action( 'admin_bar_menu', 'lit_resign_adminbar_item', 1002 );
/**
* Adds "Resign" menu item in the WordPress admin bar.
*
* @param WP_Admin_Bar $admin_bar WP_Admin_Bar instance, passed by reference.
*/
function lit_resign_adminbar_item( $admin_bar ) {
if( !class_exists( 'CT_Component' ) ) {
return;
@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 / 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 / snippet.php
Created June 16, 2019 07:33
Ensure all Embed Gutenberg Blocks are Responsive by Default
add_theme_support( 'responsive-embeds' );
@wplit
wplit / snippet.php
Created June 16, 2019 07:53
Remove Favicon Completely from WP
add_action('wp_head', 'lit_no_favicon');
function lit_no_favicon() {
echo '<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />';
}
@wplit
wplit / snippet.php
Last active June 16, 2019 08:01
Strip WP menu markup down to bare minimum
// Removes all CSS classes & ID's from menu items (only allows those listed)
add_filter('nav_menu_css_class', 'lit_strip_nav_menu');
add_filter('nav_menu_item_id', 'lit_strip_nav_menu');
function lit_strip_nav_menu($var) {
return is_array($var) ? array_intersect($var, array(
'current-menu-item',
'menu-item',
'menu-item-has-children',
'sub-menu'
)