Skip to content

Instantly share code, notes, and snippets.

View joshuafredrickson's full-sized avatar
🍊
Orange pineapple

Joshua Fredrickson joshuafredrickson

🍊
Orange pineapple
View GitHub Profile
@joshuafredrickson
joshuafredrickson / gist:5389226
Last active December 16, 2015 06:09 — forked from alkos333/gist:1771618
jQuery: Get query string variable
// Given a query string "?to=email&why=because&first=John&Last=smith"
// $.getUrlVar("to") will return "email"
(function($){
$.getUrlVar = function(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
};
})(jQuery);
@joshuafredrickson
joshuafredrickson / gist:5439867
Created April 23, 2013 00:37
WordPress - Genesis: Automatically set featured post images if missing
// Automatically set featured post images if missing
function op_auto_feature_img() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
@joshuafredrickson
joshuafredrickson / gist:5439897
Last active February 22, 2019 09:11
WordPress - Genesis: Custom "read more" link in excerpts
// Custom read more link
add_filter( 'excerpt_more', 'op_read_more_link' );
add_filter( 'get_the_content_more_link', 'op_read_more_link' );
add_filter( 'the_content_more_link', 'op_read_more_link' );
function op_read_more_link() {
return '... <a class="more-link" href="' . get_permalink() . '" rel="nofollow">Continue Reading &raquo;</a>';
}
@joshuafredrickson
joshuafredrickson / gist:5519113
Last active December 17, 2015 00:10
WordPress - Genesis: Enable Jetpack Infinite Scroll
// Add support for Jetpack Infinite Scroll
add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'footer' => 'footer',
'render' => 'genesis_do_loop',
'footer_widgets' => true
) );
@joshuafredrickson
joshuafredrickson / gist:5777770
Last active December 18, 2015 11:48
WordPress - Genesis: Modify comment form
// Modify the Genesis Default Comment Form
add_filter('genesis_comment_form_args','op_email_note');
function op_email_note() {
global $user_identity, $id;
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? ' aria-required="true"' : '' );
$commenter = wp_get_current_commenter();
if (empty($commenter['comment_author_email'])) {
@joshuafredrickson
joshuafredrickson / custom-404.php
Last active December 21, 2015 15:09
WordPress Plugin: Custom 404 -- Redirect to any page and add a message
<?php
/*
Plugin Name: Custom 404
Plugin URI: http://orangepineapple.com
Description: Send 404 page to another page or URL.
Version: 2013.08.23
Author: Orangepineapple
Author URI: http://orangepineapple.com
License: GNU GPL
*/
@joshuafredrickson
joshuafredrickson / gist:6325062
Last active December 21, 2015 15:09
Wordpress: Add wmode to Wordpress embeds
// Fix embed wmode
add_filter( 'embed_oembed_html', 'op_add_video_wmode', 10, 3);
function op_add_video_wmode($html, $url, $attr) {
if ( strpos( $html, "<embed src=" ) !== false ) {
return str_replace('</param><embed', '</param><param name="wmode" value="opaque"></param><embed wmode="opaque" ', $html);
} elseif ( strpos ( $html, 'feature=oembed' ) !== false ) {
return str_replace( 'feature=oembed', 'feature=oembed&wmode=opaque', $html );
} else {
return $html;
}
@joshuafredrickson
joshuafredrickson / .htaccess
Last active August 29, 2015 13:56
.htaccess: Force download by filetype
# Force download by filetype
<FilesMatch "\.(mp3|pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
@joshuafredrickson
joshuafredrickson / gist:9117537
Last active August 29, 2015 13:56
WordPress: Improve jpg quality
// Improve jpg quality
add_filter('jpeg_quality', 'op_jpeg_quality');
function op_jpeg_quality($arg) {
return (int)80; // value between 60-100
}
@joshuafredrickson
joshuafredrickson / .htaccess
Created April 6, 2014 15:59
.htaccess: WordPress Yoast SEO Sitemap Fix
# WordPress SEO - XML Sitemap Rewrite Fix
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^locations.kml$ /index.php?sitemap=wpseo_local_kml [L]
RewriteRule ^geo_sitemap.xml$ /index.php?sitemap=geo [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix