Skip to content

Instantly share code, notes, and snippets.

View markdcraftww's full-sized avatar

Mark Duwe markdcraftww

View GitHub Profile
wp_embed_register_handler( 'github-gist', '#https?://gist\.github\.com/([0-9]+)#', 'gist_embed_handler' );
add_shortcode( 'gist', 'gist_shortcode' );
function gist_embed_handler( $matches, $attr, $url, $rawattr ) {
return gist_shortcode( $attr, $url );
}
function gist_shortcode( $atts, $content = '' ) {
if ( empty( $atts[0] ) && empty( $content ) )
return '<!-- Missing Gist ID -->';
$id = ( ! empty( $content ) ) ? $content : $atts[0];
if ( ! is_numeric( $id ) )
@markdcraftww
markdcraftww / gist:5662244
Created May 28, 2013 12:00
Base64 Encode of a 1x1px 'spacer' gif
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">
@markdcraftww
markdcraftww / gist:5662315
Created May 28, 2013 12:10
enqueue jQuery in Wordpress
if (!is_admin()) add_action( 'wp_enqueue_scripts', 'my_jquery_enqueue', 11 );
function my_jquery_enqueue() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery.js', false, null );
wp_enqueue_script( 'jquery' );
}
@markdcraftww
markdcraftww / gist:5662316
Created May 28, 2013 12:10
Remove WordPress version
remove_action( 'wp_head', 'wp_generator' );
@markdcraftww
markdcraftww / gist:5662329
Created May 28, 2013 12:13
Prevent others hotlinking your images on WordPress
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
@markdcraftww
markdcraftww / gist:5662339
Last active December 17, 2015 19:39
Add Facebook Open Graph tags to Wordpress
in functions.php:
function wp_opengraph_for_posts() {
if ( is_singular() ) {
global $post;
setup_postdata( $post );
$output = '<meta property="og:type" content="article" />' . "\n";
$output .= '<meta property="og:title" content="' . esc_attr( get_the_title() ) . '" />' . "\n";
$output .= '<meta property="og:url" content="' . get_permalink() . '" />' . "\n";
$output .= '<meta property="og:description" content="' . esc_attr( get_the_excerpt() ) . '" />' . "\n";
if ( has_post_thumbnail() ) {
@markdcraftww
markdcraftww / gist:5662347
Created May 28, 2013 12:16
Prevent WordPress compressing jpgs
add_filter('jpeg_quality', function($arg){return 100;});