Skip to content

Instantly share code, notes, and snippets.

@simonlk
simonlk / genesis-full-width-footer.php
Created January 11, 2017 02:29
Full width widgets and site footer on Genesis framework for WordPress
<?php
/**
* Plugin Name: WooCommerce Subscriptions Redirect to Checkout
* Description: Redirect customers to the checkout page when adding a subscription to their cart (rather than the checkout page, which is the default).
* Author: Simon Kelly
* Author URI: http://www.renegade-empire.com
* Version: 1.0
* License: GPL v2
*/
@simonlk
simonlk / .htaccess
Last active November 28, 2016 08:50
WordPress load uploads from external website.
# Create .htaccess file within /wp-content/uploads/ and add the below code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} http://dev.example.com # Only perform on dev site
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://www.example.com/wp-content/uploads/$1 [L,P]
</IfModule>
// Author profile box
// Thanks Justin Busa and Viktor http://forum.wpbeaverbuilder.com/support/q/author-bio-box/
function my_author_bio($content) {
if ( is_singular('post') ) {
ob_start(); ?>
<div class="fl-author-bio clearfix media well">
<div class="fl-author-bio-thumb media-left">
<img src="<?php echo get_avatar_url( get_the_author_meta('ID'), 96 ); ?>" alt="<?php the_author(); ?>" class="media-object" />
</div>
<div class="fl-author-bio-text media-body">
@simonlk
simonlk / wordpress menu shortcode
Created July 28, 2014 23:54
Create menu shortcode
/*==================================================
Create menu shortcodes - [menu name="menu-name"]
================================================= */
function sk_menu_content_shortcode( $atts, $content = null ) {
extract( shortcode_atts(array( 'name' => null, ), $atts ) );
return wp_nav_menu( array( 'menu' => $name, 'echo' => false ) );
}
add_shortcode( 'menu', 'sk_menu_content_shortcode' );
@simonlk
simonlk / woocommerce-deny-pobox-shipping
Created June 22, 2014 04:53
WooCommerce - Don't allow shipping to PO Box addresses
add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode');
function deny_pobox_postcode( $posted ) {
global $woocommerce;
// Put postcode, address 1 and address 2 into an array
$check_address = array();
$check_address[] = isset( $posted['shipping_postcode'] ) ? $posted['shipping_postcode'] : $posted['billing_postcode'];
$check_address[] = isset( $posted['shipping_address_1'] ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
$check_address[] = isset( $posted['shipping_address_2'] ) ? $posted['shipping_address_2'] : $posted['billing_address_2'];
@simonlk
simonlk / soliloquy-link-caption
Created June 11, 2014 08:22
Add link to Soliloquy caption
@simonlk
simonlk / woocommerce-subs-start-date-edit-debug-off
Created June 10, 2014 06:34
Modify WooCommerce subscription start date without debug mode
/* Add _subscription_start_date back to the viewable order meta data */
add_filter( 'woocommerce_hidden_order_itemmeta', 'theme_hide_order_itemmeta' );
function theme_hide_order_itemmeta( $hidden_meta_keys ) {
if ( ! defined( 'WCS_DEBUG' ) || true !== WCS_DEBUG ) {
if(($key = array_search('_subscription_start_date', $hidden_meta_keys)) !== false) {
unset($hidden_meta_keys[$key]);
}
}
return $hidden_meta_keys;
}
@simonlk
simonlk / wp login logout main menu
Created June 9, 2014 20:58
Add login/logout menu to WordPress main menu
/* =====================================================
Login/logout menu button
===================================================== */
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
if( $args->theme_location == 'primary-menu' ) {
ob_start();
wp_loginout(get_permalink());
$loginoutlink = ob_get_contents();
ob_end_clean();
@simonlk
simonlk / gist:164e25293343bc502dda
Created June 1, 2014 12:24
Add/Remove custom fields in WordPress profile
/* =====================================================
Custom profile field
===================================================== */
function modify_contact_methods($profile_fields) {
// Add new fields
$profile_fields['company_name'] = 'Company Name';
// Remove old fields
unset($profile_fields['aim']);