Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / no-attributes.php
Last active October 4, 2015 20:37
Removed width and height attributes from image elements in WordPress
<?php
/**
* Removed width and height attributes from image elements in WordPress
*/
add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 );
function remove_width_attribute( $html ) {
$html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
@wpscholar
wpscholar / set-featured-image.php
Created July 24, 2012 15:57
Function to set the featured image for a given post in WordPress
@wpscholar
wpscholar / customize-wp-login.php
Created July 24, 2012 16:17
Customize the login form in WordPress
<?php
/**
* Customize the login form in WordPress
* @author Micah Wood <micah@wpscholar.com>
*/
/**
* Change the href for the logo link on login page to point to the main site
*/
add_filter( 'login_headerurl', 'change_login_headerurl' );
@wpscholar
wpscholar / greatest-common-divisor.php
Last active April 9, 2021 15:43
Euclidean algorithm - Find the greatest common divisor of two integers
<?php
/**
* Returns the greatest common divisor of two integers using the Euclidean algorithm.
*
* @param $a
* @param $b
*
* @return int
*/
function get_greatest_common_divisor( $a, $b ) {
@wpscholar
wpscholar / jquery.list-expansion.js
Created December 17, 2012 19:51
List Expansion jQuery Plugin
( function( $ ) {
$.fn.listExpansion = function( options ) {
var settings = {
expandLinkHTML : '+', // Set the HTML to display inside the 'Expand' link
collapseLinkHTML : '-' // Set the HTML to display inside the 'Collapse' link
};
return this.each( function() {
@wpscholar
wpscholar / jquery.keboardblock.js
Created December 27, 2012 18:29
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' );
}
});
@wpscholar
wpscholar / singleton.class.php
Last active September 20, 2017 23:29
An example of a singleton class
<?php
class singleton() {
private static $instance;
public static get_instance() {
return isset( self::$instance ) ? self::$instance : new self();
}
@wpscholar
wpscholar / post-meta-example.php
Last active May 9, 2022 16:37
An example of how to fetch post meta using the new WP_Post object.
<?php
/**
* Pre WordPress 3.5, this is how we had to fetch post meta
*/
$post = get_post();
$last_name = get_post_meta( $post->ID, '_last_name', true );
/**
* As of WordPress 3.5, the new WP_Post object allows us to fetch post meta this way
@wpscholar
wpscholar / jquery.disable-empty-href.js
Created January 25, 2013 19:34
Prevent all links with # as the href from doing anything
/**
* Prevent all links with # as the href from doing anything
*/
jQuery(document).ready(function($) {
$('a[href="#"]').click(function(e) {
e.preventDefault();
});
});
@wpscholar
wpscholar / jquery.external-links-new-window.js
Last active August 15, 2020 07:23
Open all external links in a new window