Skip to content

Instantly share code, notes, and snippets.

View brianpurkiss's full-sized avatar

Brian Purkiss brianpurkiss

View GitHub Profile
@brianpurkiss
brianpurkiss / docReady.js
Created March 15, 2021 13:36
jquery free document.ready alternative
// https://stackoverflow.com/questions/9899372/pure-javascript-equivalent-of-jquerys-ready-how-to-call-a-function-when-t/9899701#9899701
function docReady(fn) {
// see if DOM is already available
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
@brianpurkiss
brianpurkiss / defer-inline-js.html
Created October 29, 2020 15:54
Defer inline javascript to after DOMContentLoaded
<script>
window.addEventListener('DOMContentLoaded', function() {
(function($) {
console.log('Hello world.');
})(jQuery);
});
</script>
@brianpurkiss
brianpurkiss / wp-cli-find-replace.txt
Created August 27, 2019 20:47
Find and replace a domain (or text) through wp-cli for WordPress
wp search-replace "OLDDOMAIN" "NEWDOMAIN" --precise --skip-columns=guid,user_email --all-tables --skip-plugins --skip-themes --report-changed-only
@brianpurkiss
brianpurkiss / logged-in-sticky-nav.scss
Last active August 7, 2019 12:34
Bootstrap sticky nav padding for logged in wordpress users
body.logged-in.admin-bar {
.navbar.fixed-top { margin-top: 32px;
@media screen and ( max-width: 782px ) {
& { margin-top: 46px; }
}// end @media screen and ( max-width: 782px )
}// end .header,.navbar.fixed-top
}// end body.logged-in.admin-bar
@brianpurkiss
brianpurkiss / dequeue-bs-blocks.php
Last active June 24, 2019 15:33
Dequeue the Boostrap Block Styles
<?php
// Dequeue the Boostrap Block Styles
// The one stylesheet should be compiled with a preprocessor
function dequeue_dequeue_plugin_style(){
wp_dequeue_style( 'wp-bootstrap-blocks-styles' ); //Name of Style ID.
}
add_action( 'wp_enqueue_scripts', 'dequeue_dequeue_plugin_style', 999 );
@brianpurkiss
brianpurkiss / acf-wysiwyg-removed-p.php
Created May 15, 2019 16:26
Removing the <p> from ACF's WYSIWYG Field
<?php
// Uses a str_replace to get rid of the p tags for a ACF WYSIWYG field.
// This preserves other styling in the WYSIWYG field compared to other methods.
$text = get_field('the_field');
$stripped_text = str_replace(array('<p>','</p>'),'',$text);
echo $stripped_text;
@brianpurkiss
brianpurkiss / custom-blog-permalinks.php
Created May 14, 2019 19:55
Change the WP permalink structure of posts only
@brianpurkiss
brianpurkiss / cpt-search.php
Created May 13, 2019 14:06
Search Just a Custom Post Type
<?php /*
Search just a custom post type using WordPress' native search.
Uses Boostrap classes.
Swap out "CustomPostTypeHere" for your custom post type slug.
*/ ?>
<form class="form-inline" action="<?php echo home_url( '/' ); ?>">
@brianpurkiss
brianpurkiss / cache-buster.php
Created April 10, 2019 15:30
Auto clear visitors' cache by auto incrementing version based on theme version number
<?php
/**
* Enqueue CSS & scripts file
* The "Cache Buster" appends the theme version number as a ?ver=
* The "Cache Buster" auto increments whenever the theme's version number increments
* This gets visitors to load the new CSS/JS whenever the theme updates
*/
function bp_enqueue() {
// Increments the version number for css/js based on the theme's version number