Skip to content

Instantly share code, notes, and snippets.

View jmsmrgn's full-sized avatar
🚀

James Morgan jmsmrgn

🚀
View GitHub Profile
@jmsmrgn
jmsmrgn / clean-wp_nav_menu.php
Last active February 8, 2019 11:40
WordPress - Clean wp_nav_menu
//Deletes all CSS classes and id's, except for those listed in the array below
function custom_wp_nav_menu($var) {
return is_array($var) ? array_intersect($var, array(
//List of allowed menu classes
'first',
'last',
'current_page_item',
'current_page_parent',
'current_page_ancestor',
'current-menu-ancestor',
@jmsmrgn
jmsmrgn / fluid-equal-height-columns.js
Last active December 12, 2015 12:49
jQuery - fluid equal height columns on window resize
function resetHeight() {
var maxHeight = 0;
$(".equal-height").height("auto").each(function(){
maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
}).height(maxHeight);
}
if (window.innerWidth > 650) {
resetHeight();
}
@jmsmrgn
jmsmrgn / page-slug-body-class.php
Last active December 13, 2015 17:48
WordPress - Page Slug Body Class
// Page Slug Body Class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );
@jmsmrgn
jmsmrgn / filter-p-tags.php
Last active December 23, 2015 16:38
WordPress - Filter <p> tags from images and iFrames
//Filter <p> tags from images and iFrames
function filter_ptags_on_images($content) {
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
return preg_replace('/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
@jmsmrgn
jmsmrgn / _retina-background-images.scss
Last active December 14, 2015 11:49
SCSS - Retina Background Images Mixin
@mixin image-2x($image, $width, $height) {
@media (min--moz-device-pixel-ratio: 1.3),
(-o-min-device-pixel-ratio: 2.6/2),
(-webkit-min-device-pixel-ratio: 1.3),
(min-device-pixel-ratio: 1.3),
(min-resolution: 1.3dppx) {
/* on retina, use image that's scaled by 2 */
background-image: url($image);
background-size: $width $height;
}
@jmsmrgn
jmsmrgn / smooth-scrolling-links.js
Last active December 21, 2015 07:39
Smooth Scrolling To Internal Links With jQuery
@jmsmrgn
jmsmrgn / short-page-template-body-classes.php
Last active December 26, 2015 13:39
WordPress - Short page template body classes
function short_page_template_body_classes( $classes ){
if( is_page() ){
$template = get_page_template_slug(); // returns an empty string if it's loading the default template (page.php)
if( $template === '' ){
$classes[] = 'default-page';
} else {
$classes[] = sanitize_html_class( str_replace( '.php', '', $template ) );
}
}
return $classes;
@jmsmrgn
jmsmrgn / hide-widget-title.php
Created November 14, 2013 23:04
WordPress - Hide Widget Titles
// Add the filter and function, returning the widget title only if the first character is not "!"
add_filter( 'widget_title', 'remove_widget_title' );
function remove_widget_title( $widget_title ) {
if ( substr ( $widget_title, 0, 1 ) == '!' )
return;
else
return ( $widget_title );
}
@jmsmrgn
jmsmrgn / wp-hide-adminbar.php
Last active January 2, 2016 00:49
WordPress - Hide admin bar when viewing pages while logged in
// Hide admin bar when viewing pages while logged in
add_filter('show_admin_bar', '__return_false');
@jmsmrgn
jmsmrgn / wp-config-local.php
Last active January 2, 2016 18:29
Tell wp-config.php to use wp-config-local.php if available
if ( file_exists( dirname( __FILE__ ) . '/wp-config-local.php' ) ) {
include( dirname( __FILE__ ) . '/wp-config-local.php' );
} else {
define( 'DB_NAME', '' );
define( 'DB_USER', '' );
define( 'DB_PASSWORD', '' );
define( 'DB_HOST', '127.0.0.1' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
}