Skip to content

Instantly share code, notes, and snippets.

View byronjohnson's full-sized avatar
🧙

Byron Johnson byronjohnson

🧙
View GitHub Profile
const browserWidth = (window.innerWidth > 0) ? window.innerWidth : screen.width;
console.log(browserWidth);
/**
* Hide email from Spam Bots using a shortcode.
*
* @param array $atts Shortcode attributes. Not used.
* @param string $content The shortcode content. Should be an email address.
*
* @return string The obfuscated email address.
*/
function wpcodex_hide_email_shortcode( $atts, $content = null ) {
if ( ! is_email( $content ) ) {
(function () {
/**
* Elements
*/
const arrows = document.querySelectorAll(".mfp-arrow");
/**
* Events
@byronjohnson
byronjohnson / remove-wpcore-lazy-loading-per-class.php
Last active August 16, 2022 21:14
Remove WP Core Lazy Loading per classname
// Add remove-lazy-loading class to featured images
function add_class_to_featured_image($attr)
{
$attr['class'] .= ' remove-lazy-loading';
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'add_class_to_featured_image', 10, 1);
// Remove lazy loading from featured post images
@byronjohnson
byronjohnson / custom-permalinks.php
Created May 26, 2022 15:32
Custom permalinks for WordPress Posts
@byronjohnson
byronjohnson / add-rel-nofollow-checkbox.php
Created May 18, 2022 18:59 — forked from danielbachhuber/add-rel-nofollow-checkbox.php
Add a 'Add rel="nofollow" to link' checkbox to the WordPress link editor
<?php
/**
* Add a 'Add rel="nofollow" to link' checkbox to the WordPress link editor
*
* @see https://danielbachhuber.com/tip/rel-nofollow-link-modal/
*/
add_action( 'after_wp_tiny_mce', function(){
?>
<script>
@byronjohnson
byronjohnson / .codacy.yml
Last active May 17, 2022 15:42
Condacy Config
---
exclude_paths:
- ".*[\.-]min\.css"
- ".*[\.-]min\.js"
- ".*node_modules/.*"
- "*vendor/.*"
- ".bundle/**"
- "spec/**/*"
- "benchmarks/**/*"
- "**.min.js"
@byronjohnson
byronjohnson / php-console-log.php
Created March 16, 2022 16:52
PHP Console Log Function
/**
* Function to log PHP vars to the console
*/
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
@byronjohnson
byronjohnson / breadcrumbs-functions.php
Created November 5, 2020 19:43 — forked from tinotriste/breadcrumbs-functions.php
Wordpress: Breadcrumbs function
/*=============================================
= BREADCRUMBS =
=============================================*/
// to include in functions.php
function the_breadcrumb() {
$sep = ' > ';
if (!is_front_page()) {
@byronjohnson
byronjohnson / defer-enqueue-scripts.php
Created January 26, 2020 18:03
Defer and Async scripts that are loaded from wp_enqueue_scripts
<?php
// Selectively add async and defer attributes to scripts loaded from wp_enqueue_scripts
function defer_enqueue_scripts( $tag, $handle, $src ) {
$defer = array(
'script-one',
'script-two'
);
$async = array(