Skip to content

Instantly share code, notes, and snippets.

View nielsvr's full-sized avatar

Niels van Renselaar nielsvr

View GitHub Profile
@nielsvr
nielsvr / cleanup-yoast.php
Created October 9, 2020 08:18
Hide yoast notices and cleanup interface
<?php
/** Hide Yoast SEO alert from everywhere **/
if (is_plugin_active('wordpress-seo/wp-seo.php')) {
/* Remove HTML Comments */
add_action('get_header',function() { ob_start(function ($o) {
return preg_replace('/\n?<.*?Yoast SEO plugin.*?>/mi','',$o); }); });
add_action('wp_head',function() { ob_end_flush(); }, 999);
@nielsvr
nielsvr / functions.php
Last active March 10, 2020 06:29
Rewrite
<?php
// Should match /category/s/
// Should match /category/tag/s/
// Should match /category/tag/tag/s/
// Etcetera
// https://regex101.com/r/sNfHex/1
@nielsvr
nielsvr / functions.php
Last active November 16, 2018 10:15
Enqueue styles in Gutenberg only if the blocks are used on the post/page
<?php
add_action('enqueue_block_assets', 'maybe_enqueue_scripts_and_styles' );
function maybe_enqueue_scripts_and_styles() {
// Map blockname with CSS filename
$styles = array(
"basic" => "basic"
);
@nielsvr
nielsvr / .htaccess
Created November 5, 2018 12:08
Bad bots list for htaccess or vhosts.conf
RewriteCond %{HTTP_USER_AGENT} \
12soso|\
192\.comagent|\
1noonbot|\
1on1searchbot|\
3de\_search2|\
3d\_search|\
3g\ bot|\
3gse|\
50\.nu|\
@nielsvr
nielsvr / domains-check.sh
Created July 6, 2018 08:53
Matches a list of domains A-record against an expected IP
#!/bin/bash
# This script uses dig to retrieve the A record for domains
# Add your domains in a file called domains.txt, seperated by newlines
# Add your expected IP in a parameter -e=123.123.123.123
# Output is ok.txt with domains matching the IP, not-ok.txt with domains failing
# Parse parameters
for i in "$@"
do
case $i in
@nielsvr
nielsvr / functions.php
Last active May 31, 2017 08:17
Modify WooCommerce price for currency conversion and better decimal display
<?php
// define the raw_woocommerce_price callback
function modify_price_for_currency ( $price, $product ) {
global $post, $woocommerce;
if( !$product ) return $price;
$new_price = $price*0.89;
@nielsvr
nielsvr / regex.php
Created February 22, 2017 08:49
Validate dutch mobile phone numbers (international notation)
<?php
// Validate dutch mobile phone numbers (international notation)
if(!preg_match('/^\+[0-9]{1,2}[ ]\([0-9]{1}\)[ ]([0-9]{9})$/', $telephone)) {
$error = 'Use international notation: +31 (0) 612341234';
}
@nielsvr
nielsvr / functions.php
Created March 9, 2016 11:34
Remove Yoast SEO upgrade notices
<?php
// add to your functions.php
add_action('admin_init', 'theme_disable_yoast_notifications');
function theme_disable_yoast_notifications() {
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) ) {
@nielsvr
nielsvr / fulfillment.php
Last active January 12, 2016 07:40
Hook into the fulfillment status of Pronamic IDEAL
<?php
class Fulfillment {
/**
* Constructs and initialize
*/
public function __construct() {
<?php
add_filter('tribe_events_tickets_attendees_csv_items', 'filter_eea_csv_items', 10, 1);
function filter_eea_csv_items( $items ) {
$first = true;
foreach( $items AS $item_row => $item ) {