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 / *.php
Created January 24, 2017 04:47
Make page templates selectable for CPT "chiptuing" when using WP All Import
<?php
//* Changed file: controllers/admin/import.php ************************************************************************************
//* OLD:
$hide_fields = array('_wp_page_template', '_edit_lock', '_edit_last', '_wp_trash_meta_status', '_wp_trash_meta_time');
//* NEW:
$hide_fields = array('_edit_lock', '_edit_last', '_wp_trash_meta_status', '_wp_trash_meta_time');
@nielslange
nielslange / template-chiptuning-single.php
Last active January 24, 2017 12:08
Create dynamic chart based on original nm and upgraded nm
<?php
//* Load Google charts library
add_action( 'wp_enqueue_scripts', 'wp_enqueue_chiptuning_scripts' );
function wp_enqueue_chiptuning_scripts( ) {
wp_enqueue_script( 'google-charts-script', 'https://www.gstatic.com/charts/loader.js' );
}
//* Replace Genesis loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
@nielslange
nielslange / functions.php
Created January 31, 2017 09:32
Highlight parent menu item
<?php
//* Highlight parent menu item
add_action('nav_menu_css_class', 'nl_nav_menu_css_class', 10, 2 );
function nl_nav_menu_css_class($classes, $item) {
global $post;
$current_post_type = get_post_type_object(get_post_type($post->ID));
$current_post_type_slug = $current_post_type->rewrite['slug'];
@nielslange
nielslange / functions.php
Last active February 18, 2017 11:07
WordPress: Disable emojis
<?php
//* Disable the emoji's
add_action( 'init', 'nl_disable_wp_emojis' );
function nl_disable_wp_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
@nielslange
nielslange / functions.php
Last active February 18, 2017 11:08
WordPress: Disable embed script
<?php
//* Disable embed script
add_action('init', 'nl_disable_wp_embed');
function nl_disable_wp_embed() {
if (!is_admin()) {
wp_deregister_script('wp-embed');
}
}
@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 / functions.php
Last active February 18, 2017 14:11
Add page slug as id to widget title
<?php
//* Add page slug as id to widget title
add_filter('widget_title', 'add_slug_id_to_widget_title', 15, 3);
function add_slug_id_to_widget_title($title, $instance, $args){
$page = get_page_by_title($title);
$title = sprintf('<span id="%s">%s</span>', $page->post_name, $title);
return $title;
}
@nielslange
nielslange / functions.php
Last active February 18, 2017 14:13
Access WC variables
<?php
//* Get global WC object
global $woocommerce;
//* Access various WooCommerce cart variables, see also https://docs.woothemes.com/wc-apidocs/class-WC_Cart.html
$woocommerce->cart->get_cart_subtotal();
$woocommerce->cart->get_cart_tax();
$woocommerce->cart->get_cart_total();
//* Access various WooCommerce customer variables, see also @see https://docs.woothemes.com/wc-apidocs/class-WC_Customer.html
@nielslange
nielslange / functions.php
Last active February 18, 2017 14:14
Forward all WC email notifications
<?php
//* Forward all WC email notifications
add_filter( 'woocommerce_email_headers', 'nl_forward_wc_email_notifocations', 10, 2);
function nl_forward_wc_email_notifocations($headers, $object) {
$headers = array();
$headers[] = 'Bcc: Niels Lange <info@nielslange.com>';
$headers[] = 'Content-Type: text/html';
return $headers;
}
@nielslange
nielslange / functions.php
Last active February 18, 2017 14:16
Disable XML-RPC Pingback
<?php
//* Remove X-Pingback header
add_filter( 'wp_headers', function( $headers ) {
unset( $headers['X-Pingback'] );
return $headers;
}, 20);
//* Remove XML-RPC methods
add_filter( 'xmlrpc_methods', function( $methods ) {
unset( $methods['pingback.ping'] );