Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mglaman's full-sized avatar

Matt Glaman mglaman

View GitHub Profile
@mglaman
mglaman / wp_posts-migrate.sql
Last active December 17, 2015 20:49
Migrating WordPress websites, changing guid for posts so attachments and routes have proper URL.
UPDATE wp_posts SET guid =
REPLACE(
guid,
"localhost/example",
"example.com"
),
post_content =
REPLACE(
post_content,
"localhost/example",
@mglaman
mglaman / wp-options-permalink-set.php
Created May 29, 2013 22:53
Automatically set permalink structure when theme is activated.
@mglaman
mglaman / data-rollover.js
Created June 5, 2013 21:17
Using an element with a background-image, you can specify data-rollover="http://" to specify a rollover image.
$(document).ready(function() {
$('.rollover').each(function() {
var rollover = $(this).data('rollover');
var original = $(this).css('background-image');
$(this).hover(
function() {
$(this).css('background-image', 'url('+rollover+')');
},
function() {
$(this).css('background-image', original);
@mglaman
mglaman / wp-widget-custom-classes.php
Created June 12, 2013 02:10
Allows the ability to add custom classes to WordPress widgets (just through filter, does not add form.)
<?php
//Hook into dynamic_sidebar_params filter
//found in dynamic_siderbar ( wp-include/widgets.php ) line 886
add_filter( 'dynamic_sidebar_params', 'extend_widgets_sidebar_params', 10);
//I have my classes stored within an array in an option called widget_classes
if((!$widget_classes = get_option('widget_classes')) || !is_array($widget_classes) ) $widget_classes = array();
/* Params callback on setting widget params */
@mglaman
mglaman / Example WP Query for Staff post type
Last active March 27, 2019 00:57
Quick custom WP_Query to display all of a custom post type
<ul class="staff">
<?php $recentPosts = new WP_Query(array('posts_per_page' => -1, 'post_type' => array('staff') ));
while( $recentPosts->have_posts() ) : $recentPosts->the_post(); ?>
<li>
<div class="thumb"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail') ?></a></div>
<p class="info vcard">
<span class="name"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
<span class="title"><?php the_field('job_title'); ?></span>
<span class="email"><a href="mailto: <?php the_field('email'); ?>"><?php the_field('email'); ?></a></span>
<span class="phone"><?php the_field('phone'); ?></span>
@mglaman
mglaman / commerce_adwords_conversion_pane.info
Last active December 21, 2015 01:38
Creates a checkout pane in Drupal Commerce for Google AdWords tracking
name = Checkout Pane AdWords
description = AdWords campaign tracking (hard-coded)
package = Commerce (contrib)
dependencies[] = commerce_checkout
core = 7.x
; Information added by drupal.org packaging script on 2012-12-09
version = "7.x-1.x-dev"
core = "7.x"
project = "checkout_pane_adwords"
@mglaman
mglaman / commerce-flat-rate-calculation-rule.json
Created September 10, 2013 17:07
If you're using Flat Rate shipping on Drupal Commerce, this update rule will prevent calculation of the customer shipping profile is empty.
{ "commerce_shipping_method_flat_rate" : {
"LABEL" : "Collect rates: Flat rate",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "commerce_shipping" ],
"ON" : [ "commerce_shipping_collect_rates" ],
"IF" : [
{ "entity_has_field" : {
"entity" : [ "commerce-order" ],
"field" : "commerce_customer_shipping"
}
@mglaman
mglaman / fb_feed.php
Created September 22, 2013 17:00
WordPress plugin to add responsive Facebook Like Box widget.
<?php
/*
Plugin Name: Responsive Facebook Like Box
Plugin URI: http://glamanate.com
Description: Adds a Facebook Like Box widget which is responsive
Author: Matt Glaman
Version: 0.1-alpha
Author URI: http://glamanate.com
*/
@mglaman
mglaman / fb-likebox-example.html
Created September 22, 2013 17:07
Generic Facebook Like Box code for reference.
<div class="fb-like-box" data-href="https://www.facebook.com/FacebookDevelopers" data-width="292" data-show-faces="true" data-header="true" data-stream="true" data-show-border="true"></div>
@mglaman
mglaman / fb-resize.js
Last active December 23, 2015 16:29
Another example
$(window).bind("load resize", function(){
var container_width = $('#container').width();
$('#container').html('<div class="fb-like-box" ' +
'data-href="https://www.facebook.com/FacebookDevelopers"' +
' data-width="' + container_width + '" data-height="730" data-show-faces="false" ' +
'data-stream="true" data-header="true"></div>');
FB.XFBML.parse( );
});