Skip to content

Instantly share code, notes, and snippets.

View mike-at-redspace's full-sized avatar
🎧

Mike Vardy mike-at-redspace

🎧
View GitHub Profile
@mike-at-redspace
mike-at-redspace / is_blog.php
Created June 24, 2021 10:33 — forked from wesbos/is_blog.php
WordPress is_blog()
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
Usage:
<?php if (is_blog()) { echo 'You are on a blog page'; } ?>
@mike-at-redspace
mike-at-redspace / gist:1be0ac96b54ed4e07de18c4f369c8115
Created June 24, 2021 10:31 — forked from westonruter/gist:5475349
WordPress Fragment Caching convenience wrapper
<?php
/*
Usage:
cache_fragment_output( 'unique-key', 3600, function () {
functions_that_do_stuff_live();
these_should_echo();
});
*/
function cache_fragment_output( $key, $ttl, $function ) {
@mike-at-redspace
mike-at-redspace / wp-chosen-tax-metabox.php
Created June 24, 2021 10:28 — forked from helen/wp-chosen-tax-metabox.php
Use Chosen for a replacement WordPress taxonomy metabox
<?php
/**
* WordPress Chosen Taxonomy Metabox
* Author: Helen Hou-Sandi
*
* Use Chosen for a replacement taxonomy metabox in WordPress
* Useful for taxonomies that aren't changed much on the fly and are
* non-hierarchical in nature, as Chosen is for flat selection only.
* You can always use the taxonomy admin screen to add/edit taxonomy terms.
* Categories need slightly different treatment from the rest in order to
@mike-at-redspace
mike-at-redspace / whatissoslow.php
Created June 24, 2021 10:28 — forked from Viper007Bond/whatissoslow.php
WordPress: Times how long it takes each filter and action to run and displays results at the end of the page. Quick and dirty.
<?php
/**
* This little class records how long it takes each WordPress action or filter
* to execute which gives a good indicator of what hooks are being slow.
* You can then debug those hooks to see what hooked functions are causing problems.
*
* This class does NOT time the core WordPress code that is being run between hooks.
* You could use similar code to this that doesn't have an end processor to do that.
*
@mike-at-redspace
mike-at-redspace / functions.php
Created June 24, 2021 10:28 — forked from tripflex/functions.php
WordPress Remove Filter (remove_filter converted to remove_class_filter) to remove Filter/Action without Class Object access. Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
<?php
/**
* Make sure the function does not exist before defining it
*/
if( ! function_exists( 'remove_class_filter' ) ){
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback
@mike-at-redspace
mike-at-redspace / wordpress-firebase.php
Created June 24, 2021 10:25 — forked from derekconjar/wordpress-firebase.php
An example of using Firebase and WordPress together. The idea is to use WP's custom post types and metaboxes to make content management easy, and sync with Firebase so that your websites have access to a real-time JSON feed of your custom data.
<?php
/**
* All custom functions should be defined in this class
* and tied to WP hooks/filters w/in the constructor method
*/
class Custom_Functions {
// Custom metaboxes and fields configuration
@mike-at-redspace
mike-at-redspace / example-wp-list-table.php
Created June 24, 2021 10:24 — forked from paulund/example-wp-list-table.php
An example code of using the WP_List_Table class. With Pagination.
<?php
/*
* Plugin Name: Paulund WP List Table Example
* Description: An example of how to use the WP_List_Table class to display data in your WordPress Admin area
* Plugin URI: http://www.paulund.co.uk
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* Version: 1.0
* License: GPL2
*/
@mike-at-redspace
mike-at-redspace / customizer.php
Created June 24, 2021 10:17
WordPress Theme Customizer Boilerplate
<?php
function themename_customize_register($wp_customize){
$wp_customize->add_section('themename_color_scheme', array(
'title' => __('Color Scheme', 'themename'),
'priority' => 120,
));
// =============================
@mike-at-redspace
mike-at-redspace / hero.php
Created June 24, 2021 10:12
Youtube Video Hero
<section class="hero">
<div class="hero--video clearfix">
<div class="inner-hero-video">
<div id="wrapperVideoBanner" class="wrapper-video--banner video-wrapper videoWrapper169">
<iframe class="video-iframe" width="1920" height="1080" src="" frameborder="0" allowTransparency="true" allowfullscreen data-src="https://www.youtube.com/embed/[videoid]?autoplay=1&amp;showinfo=0"></iframe>
<!-- the poster frame - in the form of a button to make it keyboard accessible -->
<button id="videoPlay" class="video-poster" style="background-image:url( <?php echo get_template_directory_uri() . '/assets/images/placeholders/test.jpg' ?>);">Play video</button>
<button id="videoStop">Stop video</button>
</div>
@mike-at-redspace
mike-at-redspace / touch.js
Created June 24, 2021 10:08
Detect Touch
export function detectTouch() {
window.addEventListener('touchstart', function onFirstTouch() {
// we could use a class
document.body.classList.add('user-is-touching');
// or set some global variable
// window.USER_IS_TOUCHING = true;
// or set your app's state however you normally would
// frameworkOfChoice.dispatchEvent('USER_IS_TOUCHING', true);