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 14:19
Trim length of featured post title
<?php
//* Trim length of featured post title
add_filter( 'genesis_featured_post_title', 'smntcs_genesis_featured_post_title' );
function smntcs_genesis_featured_post_title( $title ) {
return mb_strimwidth($title, 0, 65, '...');
}
@nielslange
nielslange / functions.php
Last active February 18, 2017 14:18
Add link shortcode to widget title
<?php
//* Add link shortcode to widget title
//* Usage: [link href = https://www.google.com]Google[link]
add_filter( 'widget_title', 'link_widget_title' );
function link_widget_title( $title ) {
$title = str_replace( '[link', '<a', $title );
$title = str_replace( '[/link]', '</a>', $title );
$title = str_replace( ']', '>', $title );
return $title;
@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'] );
@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 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 / .gitignore
Last active February 20, 2017 07:29
WordPress .gitignore
# Ignore everything in the root except the "wp-content" directory, the config
# fies and the meta files.
/*
.*
~*
!wp-content/
!.gitignore
!.htaccess
!.htpasswd
!README.md
@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');
}
}