Skip to content

Instantly share code, notes, and snippets.

@andyknapp
andyknapp / no-p-tags.php
Created March 31, 2014 12:31
Strip <p> tags from images within the_content in WordPress
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
@andyknapp
andyknapp / register-img-sizes-wp.php
Last active August 29, 2015 14:00
Register image sizes - WordPress
/* register additional image sizes */
function ak_insert_custom_image_sizes( $image_sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
if ( empty( $_wp_additional_image_sizes ) )
return $image_sizes;
// add all the custom sizes to the built-in sizes
foreach ( $_wp_additional_image_sizes as $id => $data ) {
@andyknapp
andyknapp / triangles.scss
Created June 8, 2014 17:26
Sass mixins for triangles
@mixin rt-triangle($h, $depth, $color, $top: 0, $left: 100%) {
content: '';
display: inline-block;
position: absolute;
top: $top;
left: $left;
width: 0;
height: 0;
border-top: $h/2 solid transparent;
border-left: $h*$depth solid $color;
@andyknapp
andyknapp / menu-toggle.js
Created June 8, 2014 17:35
Custom responsive menu for _s
jQuery(document).ready(function($) {
/* menu toggle */
$('.menu-toggle').click(function() {
$('#site-navigation, .menu-toggle').toggleClass('toggled');
})
});
@andyknapp
andyknapp / remove-default-value.js
Created June 8, 2014 17:37
Remove default value on ::focus in gravity forms
jQuery(document).ready(function($) {
$('.gform_wrapper input[type=text], .gform_wrapper input[type=email], .gform_wrapper textarea, .gform_wrapper input[type=tel]').each(function() {
$.data(this, 'default', this.value);
}).focus(function() {
if ($.data(this, 'default') == this.value) {
this.value = '';
$(this).addClass('focus-value');
}
}).blur(function() {
if (this.value == '') {
@andyknapp
andyknapp / smoothscroll.js
Created June 13, 2014 20:07
smooth scroll for links on same page (via css-tricks)
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
// disable gravity forms confirmation msg anchor functionality
add_filter('gform_confirmation_anchor', create_function('', 'return false;'));
@andyknapp
andyknapp / functions.php
Last active December 18, 2015 17:39
Removes WordPress sign-in error message
add_filter ( 'login_errors', create_function ('$a', "return null;"));
@andyknapp
andyknapp / functions.php
Last active December 18, 2015 17:39
Remove WP version number from head
remove_action( 'wp_head', 'wp_generator');
@andyknapp
andyknapp / functions.php
Last active December 18, 2015 17:39
Custom logo on WP login screen
function ak_custom_login_logo() {
wp_enqueue_style( 'ak_custom_login_logo', get_stylesheet_directory_uri() . '/login.css' );
}
add_action('login_head', 'ak_smj_custom_login_logo');