Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻

Michael Wender mwender

👨‍💻
View GitHub Profile
@mwender
mwender / htaccess-alias-redirect
Created Jun 17, 2015
Redirect all domain aliases to one with these .htaccess rules.
View htaccess-alias-redirect
RewriteEngine On
# If the hostname is NOT www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
# 301 redirect to the same resource on www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
@mwender
mwender / visual-composer-html-id-option.php
Last active Nov 23, 2017
Add an HTML ID option to Visual Composer rows in the X Theme
View visual-composer-html-id-option.php
<?php
function x_child_visual_composer_update_existing_shortcodes(){
if ( function_exists( 'vc_add_param' ) ) {
vc_add_param( 'vc_row', array(
'type' => 'textfield',
'heading' => "HTML ID",
'param_name' => 'element_id',
'value' => '',
'description' => __( "Assign an ID to the row", "discprofile" ),
) );
@mwender
mwender / impbcopy.m
Last active Nov 26, 2022
Command line copy an image file to the clipboard in Mac OS X. See first comment for install instructions.
View impbcopy.m
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <unistd.h>
BOOL copy_to_clipboard(NSString *path)
{
// http://stackoverflow.com/questions/2681630/how-to-read-png-image-to-nsimage
NSImage * image;
if([path isEqualToString:@"-"])
{
// http://caiustheory.com/read-standard-input-using-objective-c
@mwender
mwender / recent_feed_posts_shortcode.php
Created Nov 26, 2013
Revised shortcode handling for a recent posts widget that pulls content from an RSS feed. For use in a child theme of Avada.
View recent_feed_posts_shortcode.php
add_shortcode('mcm_recent_feed_posts', 'shortcode_mcm_recent_feed_posts');
/**
* shortcode_mcm_recent_feed_posts() - Retrieves posts from RSS feed
*
* @see fetch_feed()
*
* @since 1.0.0
*
* @param array $atts {
* @type string $url RSS feed URL.
@mwender
mwender / jquery_ajax_request.js
Created Nov 25, 2013
Example jQuery AJAX request
View jquery_ajax_request.js
jQuery( function($){
$( 'a.button' ).click( function( e ){
$.post( '?qa=default', { var1: var1, var2: var2 }, function( data ){
console.log( '[jQuery AJAX Request] ' + data.message );
});
e.preventDefault();
});
});
@mwender
mwender / wordpress_query_functions.php
Created Nov 25, 2013
Functions which allow querying WordPress directly. Useful for AJAX callbacks.
View wordpress_query_functions.php
add_filter( 'query_vars', 'theme_query_vars' );
/**
* Adds variables to $wp->query_vars
*
* @param array $vars Global WP query vars.
* @return array Array used in $wp->query_vars.
*/
function theme_query_vars( $vars ){
$vars[] = 'qa'; // "query_action" - used for switch in theme_parse_request()
return $vars;
@mwender
mwender / table_html.html
Created Nov 14, 2013
Properly formatted table HTML for use on new.triadsemi.com
View table_html.html
<table>
<caption>Wafer Fab</caption>
<colgroup>
<col style="width: 25%;" />
<col style="width: 25%;" />
<col style="width: 25%;" />
<col style="width: 25%;" />
</colgroup>
<thead>
<tr>
@mwender
mwender / force_ie_edge_rendering.php
Created Nov 8, 2013
Force IE to render a site in the latest version of its rendering engine. Useful to add to functions.php for WordPress themes.
View force_ie_edge_rendering.php
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) )
header('X-UA-Compatible: IE=edge,chrome=1');
@mwender
mwender / rackspace_cloud_sites_gen_ssh_key.sh
Created Nov 6, 2013
Generate an SSH key for your Rackspace Cloud Site. Replace _REMOTE_REPO_HOST_ with the domain of your remote repo host (e.g. bitbucket.org, github.com, etc). Upload this script somewhere above your web root and run it as a Perl cron. After it runs you'll find `id_rsa.pub` in /.ssh/.
View rackspace_cloud_sites_gen_ssh_key.sh
#!/bin/sh
cd .ssh
ssh-keygen -trsa -fid_rsa
ssh-keyscan -t rsa _REMOTE_REPO_HOST_ >> known_hosts
@mwender
mwender / functions.php
Created Oct 17, 2013
Remove features from WordPress parent theme. Great for removing things like shortcodes.
View functions.php
add_action( 'after_setup_theme', 'remove_parent_theme_features', 10 );
function remove_parent_theme_features(){
// remove shortcode from parent theme
remove_shortcode( 'example' );
// replace with child theme shortcode callback
add_shortcode( 'example', 'child_theme_example_callback' );
}