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
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;
}
@nielslange
nielslange / functions.php
Created March 21, 2017 05:45
Exclude widget categories
<?php
/***
* Exclude widget categories
*
* Online Workshop --> ID: 967
* Online Workshop Bonus --> ID: 1081
*/
add_filter('widget_categories_args','nl_exclude_widget_categories');
function nl_exclude_widget_categories($args){
$exclude = '967,1081';
<!doctype>
<html>
<head>
<style type="text/css">
html, body {
height: 100%;
overflow: hidden;
}
h3 {
margin-bottom: 20px;
@nielslange
nielslange / .htaccess
Last active March 24, 2017 17:45
Define 401 resources and custom error page (see also https://gist.github.com/nielslange/053a3bedfb13d961bedb138a88dc943b)
# 410 Redirect Settings
ErrorDocument 410 /wp-content/themes/CHILD-THEME/410.php
Redirect 410 /GONE-PAGE.html
Redirect 410 /GONE-DIRECTORY
@nielslange
nielslange / functions.php
Created April 6, 2017 10:11
Overwrite apply_filters()
<?php
//* Overwrite WC Memberships product purchasing restricted message
add_filter( 'wc_memberships_product_purchasing_restricted_message','nl_wc_memberships_product_purchasing_restricted_message',99);
function nl_wc_memberships_product_purchasing_restricted_message( $custom_hello_text ) {
$custom_hello_text = 'Hello World';
return $custom_hello_text;
}
@nielslange
nielslange / functions.php
Created April 6, 2017 10:12
Debug loaded text domains
<?php
//* Debug loaded text domains
add_action('load_textdomain','debug_load_textdomain', 10, 2);
function debug_load_textdomain($domain , $mofile){
printf('Trying <strong>%s</strong> at %s<br>', $domain, $mofile);
}
@nielslange
nielslange / functions.php
Last active May 27, 2017 04:08
Disable plugin updates
<?php
//* Disable plugin updates
add_filter( 'site_transient_update_plugins', 'nl_disable_plugin_updates' );
function nl_disable_plugin_updates( $value ) {
unset( $value->response['woocommerce/woocommerce.php'] );
return $value;
}
@nielslange
nielslange / functions.php
Created May 29, 2017 08:03
Remove image class
<?php
//* Return empty image class
add_filter('get_image_tag_class', '__return_empty_string');
//* Remove entire image class
add_filter('get_image_tag', 'nl_remove_image_class');
function nl_remove_image_class($html) {
return preg_replace('/ class="(.*)"/', '', $html);
}
@nielslange
nielslange / README.md
Last active July 4, 2017 11:19
WooCommerce snippets