Skip to content

Instantly share code, notes, and snippets.

View rjv's full-sized avatar

Roger Vandawalker rjv

View GitHub Profile
@rjv
rjv / external-new-window
Last active January 2, 2016 17:38
Open external links in a new window
// create custom selector for external links
$.expr[':'].external = function(obj){
var $this = $(obj);
return !$this.is('[href^="mailto:"]') && !$this.is('[href^="javascript:"]') && (obj.hostname != location.hostname) && ($this.data('target') != "top");
};
// DOM is ready
$(function(){
// apply target="_blank" to each external link on the page
document.querySelectorAll('[target=_blank]').forEach(function(target) {
target.setAttribute("rel", "noopener noreferrer");
});
@rjv
rjv / functions.php
Last active February 13, 2018 19:45
Helper function for getting the featured image URL attached to a post (WordPress)
<?php
function get_thumbnail_url($post_id = null, $size = 'medium')
{
global $post;
if (is_string($post_id)) {
$size = $post_id;
$post_id = $post->ID;
}