Skip to content

Instantly share code, notes, and snippets.

@marcbacon
marcbacon / Perfect URL.php
Created July 28, 2015 14:44
Make sure that URL's are free of unwanted characters. WordPress escape URL
$my_url = 'http://marcbacon.com/?awesome=true';
$url = esc_url( $my_url );
@marcbacon
marcbacon / Perfect JPG.php
Last active August 29, 2015 14:26
Force perfect .jpg images in WordPress, remove compression.
/*
-- Add to a plugin or functions.php
*/
add_filter( 'jpg_quality', 'high_jpg_quality' );
function high_jpg_quality() {
return 100;
}
@marcbacon
marcbacon / WordPress Error Testing.php
Created July 28, 2015 14:01
Display Errors WordPress
// Switch on debugging
define('WP_DEBUG', true);
// Direct WordPress to the debug log file /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
// PHP 'display_errors' variable is not forced
@marcbacon
marcbacon / Scroll Direction.js
Created June 26, 2015 18:53
Detect scroll direction using jQuery
var iScrollPos = 0;
$(window).scroll(function () {
var iCurScrollPos = $(this).scrollTop();
if (iCurScrollPos > iScrollPos) {
//Scrolling Down
} else {
//Scrolling Up
}
iScrollPos = iCurScrollPos;
@marcbacon
marcbacon / Redirect on Login.php
Last active August 29, 2015 14:22
If a visitor is not logged into the WordPress site, send them directly to the login page. After they have logged in, redirect them back to the home page.
// Place in functions.php or in a plugin
function redirection() {
if ( ! is_user_logged_in() ) {
wp_redirect( '/wp-login.php?redirect_to=' . home_url() );
exit;
}
} // end function
add_action( 'get_header', 'redirection' );
@marcbacon
marcbacon / Bootstrap Carousel Item Normalization.js
Last active August 19, 2018 22:12
jQuery function to set all Bootstrap Carousel items to the same height.
@marcbacon
marcbacon / jQuery Click.js
Last active August 29, 2015 14:20
jQuery .click function
$('.class').click(function() {
//do stuff on click
});
@marcbacon
marcbacon / jQuery Hover.js
Last active August 29, 2015 14:20
jQuery .hover function
$('.class').hover(
function() {
//do stuff on hover
}, function() {
//do stuff after hover
}
);
@marcbacon
marcbacon / WordPress wp-config settings.php
Last active October 18, 2017 21:04
[Misc. settings for wp-config.php] #wordpress
// Limit post revisions to 2
define( 'WP_POST_REVISIONS', 2 );
// Save queries
define('SAVEQUERIES', true);
// Move uploads folder
define( 'UPLOADS', 'blog/wp-content/uploads' );
// Disable Cron
@marcbacon
marcbacon / Change Domain WordPress.php
Last active October 18, 2017 21:03
[Change a WordPress Domain] Used to change a WordPress site's domain. #wordpress
//In wp-config.php:
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
//In functions.php:
update_option('siteurl','http://example.com');
update_option('home','http://example.com');