Skip to content

Instantly share code, notes, and snippets.

View nielslange's full-sized avatar
👨‍💻
Moving bits and bytes around the globe

Niels Lange nielslange

👨‍💻
Moving bits and bytes around the globe
View GitHub Profile
@nielslange
nielslange / functions.php
Last active February 18, 2017 13:59
WordPress: Remove query strings
<?php
//* Remove query strings
add_filter( 'script_loader_src', 'nl_remove_query_strings', 15, 1 );
add_filter( 'style_loader_src', 'nl_remove_query_strings', 15, 1 );
function nl_remove_query_strings( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
@nielslange
nielslange / README.md
Last active March 23, 2023 03:28
WordPress snippets

WordPress snippets

Security snippets

Improve WordPress security (.htaccess)

# Enable .htpasswd authentication
<If "%{HTTP_HOST} != 'dev'">
AuthType Basic
AuthName "Login to dashboard"
@nielslange
nielslange / README.md
Last active April 15, 2024 18:25
Genesis Framework snippets

Genesis Framework snippets

Accessibility

Enable Accessibility Features

  • functions.php:
//* Enable Genesis Accessibility Components
add_theme_support( 'genesis-accessibility', array( '404-page', 'drop-down-menu', 'headings', 'rems', 'search-form', 'skip-links' ) );
@nielslange
nielslange / README.md
Last active July 4, 2017 11:19
WooCommerce snippets
@nielslange
nielslange / functions.php
Created February 19, 2017 05:28
WooCommerce: Add a basic surcharge to all transactions
<?php
/**
* Add a 1% surcharge to your cart / checkout
* change the $percentage to set the surcharge to a value to suit
* Uses the WooCommerce fees API
*
* Add to theme functions.php
*/
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
@nielslange
nielslange / country_surcharge.php
Last active June 17, 2022 11:04
WooCommerce: Add a surcharge based on the delivery country
<?php
/**
* Add a 1% surcharge to your cart / checkout based on delivery country
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
*
* Change $percentage to set the surcharge to a value to suit
*
* Add countries to array('US'); to include more countries to surcharge
* http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes for available alpha-2 country codes
*
@nielslange
nielslange / functions.php
Created February 19, 2017 05:34
WooCommerce: Change breadcrumb home text
<?php
//* Change breadcrumb home text
add_filter( 'woocommerce_breadcrumb_defaults', 'nl_change_breadcrumb_home_text' );
function nl_change_breadcrumb_home_text( $defaults ) {
$defaults['home'] = 'Start';
return $defaults;
}
@nielslange
nielslange / functions.php
Created February 19, 2017 05:42
WooCommerce: Change the breadcrumb separator
<?php
//* Change the breadcrumb separator from '/' to '»'
add_filter( 'woocommerce_breadcrumb_defaults', 'nl_change_breadcrumb_delimiter' );
function nl_change_breadcrumb_delimiter( $defaults ) {
$defaults['delimiter'] = ' &raquo; ';
return $defaults;
}
@nielslange
nielslange / functions.php
Created March 8, 2017 11:44
Keep links in Excerpts
<?php
/**
* Keep links in Excerpts
*
* @package WordPress
* @subpackage BeTheme Child
* @since BeTheme Child 1.0
*/
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'nl_wp_trim_excerpt');
@nielslange
nielslange / functions.php
Last active March 15, 2017 07:06
Exclude CPT for search results
<?php
//* Exclude CPT for search results
add_filter('pre_get_posts', 'nl_exclude_cpt_from_search');
function nl_exclude_cpt_from_search($query) {
if (!$query->is_admin && $query->is_search) {
$query->set('post_type', array('post', 'page', 'cpt-slug-to-include'));
}
return $query;
}