Skip to content

Instantly share code, notes, and snippets.

View jimboobrien's full-sized avatar

Jimobrien jimboobrien

View GitHub Profile
@jimboobrien
jimboobrien / jquery.keboardblock.js
Created September 20, 2017 23:29 — forked from wpscholar/jquery.keboardblock.js
Prevent the display of the pop-up keyboard on mobile devices
/**
* Using this snippet of code, just add the 'mobile-no-keyboard' class to your input or textarea
* to prevent the keyboard display on most mobile devices. You can just add the 'readonly' attribute,
* but there may be reasons you don't want to on a desktop/laptop machine.
*/
jQuery(document).ready(function($) {
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
$('input.mobile-no-keyboard, textarea.mobile-no-keyboard').attr( 'readonly', 'readonly' );
}
});
@jimboobrien
jimboobrien / singleton.class.php
Created September 20, 2017 23:29 — forked from wpscholar/singleton.class.php
An example of a singleton class
<?php
class singleton() {
private static $instance;
public static get_instance() {
return isset( self::$instance ) ? self::$instance : new self();
}
@jimboobrien
jimboobrien / jquery.external-links-new-window.js
Created September 20, 2017 23:28 — forked from wpscholar/jquery.external-links-new-window.js
Open all external links in a new window
@jimboobrien
jimboobrien / replace-wp-dashboard.php
Created September 20, 2017 23:28 — forked from wpscholar/replace-wp-dashboard.php
Replace the default WordPress dashboard with a custom one
<?php
/**
* Plugin Name: Replace WordPress Dashboard
* Description: Replaces the default WordPress dashboard with a custom one.
* Author: Micah Wood
* Author URI: http://micahwood.me
* Version: 0.1
* License: GPL3
*/
@jimboobrien
jimboobrien / functions.php
Created September 20, 2017 23:28 — forked from wpscholar/functions.php
Enqueueing IE conditional stylesheets in WordPress the right way
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_my_styles' );
/**
* Example callback function that demonstrates how to properly enqueue conditional stylesheets in WordPress for IE.
* IE10 and up does not support conditional comments in standards mode.
*
* @uses wp_style_add_data() WordPress function to add the conditional data.
* @link https://developer.wordpress.org/reference/functions/wp_style_add_data/
@jimboobrien
jimboobrien / shortcode.class.php
Created September 20, 2017 23:27 — forked from wpscholar/shortcode.class.php
Creating a class to handle a WordPress shortcode is overkill in most cases. However, it is extremely handy when your shortcode requires helper functions.
<?php
/**
* Creating a class to handle a WordPress shortcode is overkill in most cases.
* However, it is extremely handy when your shortcode requires helper functions.
*/
class My_Shortcode {
protected
$atts = array(),
@jimboobrien
jimboobrien / jquery.positionRelativeTo.js
Created September 20, 2017 23:27 — forked from wpscholar/jquery.positionRelativeTo.js
A jQuery plugin that will position an element relative to another element, regardles of whether or not they share the same parent in the DOM.
(function ( $ ) {
/**
* A jQuery plugin that will position an element relative to another element, regardles of whether or not they share the
* same parent in the DOM.
*
* Note: This must be called within a $(document).ready() call to work properly. If loading images in the element
* that aren't specifically sized via CSS, it may be necessary to call this within a $(window).load() call
* depending on the positioning used.
*
@jimboobrien
jimboobrien / jquery.toggleElement.js
Created September 20, 2017 23:27 — forked from wpscholar/jquery.toggleElement.js
A jQuery plugin that will toggle the display of an element when another element is clicked. When the toggled element is being displayed, clicking on the initiating element or any other element that is not the toggled element or its children will cause the toggled element to be hidden. Works on touchscreens.
(function( $ ) {
/**
* A jQuery plugin that will toggle the display of an element when another element is clicked.
* When the toggled element is being displayed, clicking on the initiating element or any other element that
* is not the toggled element or its children will cause the toggled element to be hidden.
*
* @param $el
* @returns {*}
*/
@jimboobrien
jimboobrien / local-time.php
Created September 20, 2017 23:26 — forked from wpscholar/local-time.php
Properly fetch the local date / time in WordPress based on a Unix timestamp.
<?php
/**
* Fetch the local date/time in WordPress based on a Unix timestamp.
*
* @param int $timestamp
* @param string $format
* @return string
*/
function get_wp_local_date_time( $timestamp, $format = '' ) {
@jimboobrien
jimboobrien / excerpt.php
Created September 20, 2017 23:19 — forked from wpscholar/excerpt.php
Generate an excerpt from provided content. Strips HTML, removes trailing punctuation and adds a 'more' string when text has been removed.
<?php
/**
* Get an excerpt
*
* @param string $content The content to be transformed
* @param int $length The number of words
* @param string $more The text to be displayed at the end, if shortened
* @return string
*/