This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to set the featured image for a given post in WordPress | |
* | |
* @author Micah Wood <micah@wpscholar.com> | |
* @param int $post_id The ID of the post for which we are setting the featured image | |
* @param int $attachment_id The ID of the attachment we want to use as the featured image | |
*/ | |
function set_featured_image( $post_id, $attachment_id ){ | |
update_post_meta( $post_id, '_thumbnail_id', $attachment_id ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( 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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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' ); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class singleton() { | |
private static $instance; | |
public static get_instance() { | |
return isset( self::$instance ) ? self::$instance : new self(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Prevent all links with # as the href from doing anything | |
*/ | |
jQuery(document).ready(function($) { | |
$('a[href="#"]').click(function(e) { | |
e.preventDefault(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Open all external links in a new window | |
*/ | |
jQuery(document).ready(function($) { | |
$('a') | |
.filter('[href^="http"], [href^="//"]') | |
.not('[href*="' + window.location.host + '"]') | |
.attr('rel', 'noopener noreferrer') | |
.attr('target', '_blank'); | |
}); |