Skip to content

Instantly share code, notes, and snippets.

View stellarcowboy's full-sized avatar

Kenneth White stellarcowboy

View GitHub Profile
@stellarcowboy
stellarcowboy / gist:f1670515c15bcafdf7a49e8c3bcfd33e
Created January 11, 2017 19:04
Add URL parameters to YouTube oembed in WordPress
/**
* youtube_embed_url_parameters function.
*
* @access public
* @param string $html
* @param string $url
* @param array $args
* @return string $html
*/
function youtube_embed_url_parameters( $html, $url, $args ) {
@stellarcowboy
stellarcowboy / gist:eba8a07af3b3ad67f96b
Last active August 29, 2015 14:16
Typical metaquery SCSS selector
.section-inner {
width:100%;
margin: 0 auto;
.breakpoint-desktop & {
width:60em;
background-color: transparent;
}
}
ul.logo-tagline {
@stellarcowboy
stellarcowboy / gist:c4eb5c93876c75c0e333
Created March 12, 2015 16:17
WordPress script enqueues for metaquery and matchMedia
wp_register_script('match_media', get_stylesheet_directory_uri().'/js/matchMedia.js', array('jquery'));
wp_enqueue_script('match_media');
wp_register_script('metaquery', get_stylesheet_directory_uri().'/js/metaquery.min.js', array('jquery','match_media'));
wp_enqueue_script('metaquery');
@stellarcowboy
stellarcowboy / gist:f76776443ef5c663092e
Created March 12, 2015 16:13
Typical metaquery breakpoints
<meta media="(max-width: 480px)" content="mobile" name="breakpoint" >
<meta media="(min-width: 481px)" content="mobilelarge" name="breakpoint" >
<meta media="(max-width: 1024px)" content="mobile-tablet" name="breakpoint" >
<meta media="(min-width: 768px)" content="tablet" name="breakpoint" >
<meta media="(min-width: 1016px)" content="desktop" name="breakpoint" >
@stellarcowboy
stellarcowboy / gist:5240867
Last active December 15, 2015 09:49
WordPress: Pass post-meta image URL to processor for thumbnails
<?php $image_grabbed = substr_replace(get_post_meta($post->ID,{field_key},true), '-150x150', -4, 0); ?>
<?php echo $image_grabbed;?>
@stellarcowboy
stellarcowboy / gist:4574479
Last active December 11, 2015 08:38
WordPress: Fix pagination for static homepage with augmented query
// Fix pagination for static homepage with augmented query
function modify_query($query) {
if($query->is_main_query()) {
if (! get_query_var('paged')) {
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$query->set('paged',$paged);
}
}
}
add_action( 'pre_get_posts', 'modify_query' );
@stellarcowboy
stellarcowboy / index.php
Last active December 11, 2015 06:39
Test a database connection before installing WordPress
<?php
$server = "localhost";
$database = "database";
$username = "user";
$password = "password";
$mysqlConnection = mysql_connect($server, $username, $password);
if (!$mysqlConnection)
{
echo "Please try later.";
@stellarcowboy
stellarcowboy / gist:4524909
Last active December 11, 2015 01:39
Given multiple rows of divs, equalize height of divs within each row.
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$('.blocks').each(function() {
$el = $(this);
topPostion = $el.position().top;
@stellarcowboy
stellarcowboy / gist:3130778
Created July 17, 2012 17:44
Correct the gallery URL attachemnt field WordPress
// Corrects the gallery URL attachment that disallows custom URLS
// Use get_post_meta( ATTACHMENT_ID_HERE, '_wp_attachment_url', true ) to retrieve
function _save_attachment_url($post, $attachment) {
if ( isset($attachment['url']) )
update_post_meta( $post['ID'], '_wp_attachment_url', esc_url_raw($attachment['url']) );
return $post;
}
add_filter('attachment_fields_to_save', '_save_attachment_url', 10, 2);
function _replace_attachment_url($form_fields, $post) {
@stellarcowboy
stellarcowboy / gist:2932639
Created June 14, 2012 20:13
Stop wordpress from wrapping images in <p> tags
// stop wordpress from wrapping images in <p> tags
function filter_ptags_on_images($content)
{
// do a regular expression replace...
// find all p tags that have just
// <p>maybe some white space<img all stuff up to /> then maybe whitespace </p>
// replace it with just the image tag...
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}