Skip to content

Instantly share code, notes, and snippets.

@jmsmrgn
jmsmrgn / clean-wp_nav_menu.php
Last active Feb 8, 2019
WordPress - Clean wp_nav_menu
View clean-wp_nav_menu.php
//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 Dec 12, 2015
jQuery - fluid equal height columns on window resize
View fluid-equal-height-columns.js
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 Dec 13, 2015
WordPress - Page Slug Body Class
View page-slug-body-class.php
// 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 Dec 23, 2015
WordPress - Filter <p> tags from images and iFrames
View filter-p-tags.php
//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 Dec 14, 2015
SCSS - Retina Background Images Mixin
View _retina-background-images.scss
@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 Dec 21, 2015
Smooth Scrolling To Internal Links With jQuery
View smooth-scrolling-links.js
@jmsmrgn
jmsmrgn / short-page-template-body-classes.php
Last active Dec 26, 2015
WordPress - Short page template body classes
View short-page-template-body-classes.php
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 Nov 14, 2013
WordPress - Hide Widget Titles
View hide-widget-title.php
// 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 Jan 2, 2016
WordPress - Hide admin bar when viewing pages while logged in
View wp-hide-adminbar.php
// Hide admin bar when viewing pages while logged in
add_filter('show_admin_bar', '__return_false');
@jmsmrgn
jmsmrgn / wp-config-local.php
Last active Jan 2, 2016
Tell wp-config.php to use wp-config-local.php if available
View wp-config-local.php
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', '' );
}