Skip to content

Instantly share code, notes, and snippets.

View Tabrisrp's full-sized avatar

Rémy Perona Tabrisrp

View GitHub Profile
@Tabrisrp
Tabrisrp / rocket-root-path-rewrite.php
Created November 1, 2018 13:08
Change default root for path rewrite
add_filter( 'rocket_min_documentRoot', function( $document_root ) {
return ABSPATH;
} );
@Tabrisrp
Tabrisrp / preload-cookies.php
Created October 29, 2018 17:54
Preload with mandatory/dynamic cookies
add_filter( 'rocket_partial_preload_url_request_args', 'rocket_add_cookie_preload' );
add_filter( 'rocket_preload_url_request_args', 'rocket_add_cookie_preload' );
function rocket_add_cookie_preload( $args ) {
$cookies = [
new WP_Http_Cookie(
[
'name' => 'cookie_notice_accepted',
'value' => 'true',
] ),
@Tabrisrp
Tabrisrp / rocket-cache-feed.php
Last active October 11, 2018 14:59
Allow caching of WP feed by WP Rocket
function wp_rocket_cache_feed( $uri ) {
$feed = '/(.+/)?' . $GLOBALS['wp_rewrite']->feed_base . '/?';
if ( in_array( $feed, $uri ) ) {
$uri = array_flip( $uri );
unset( $uri[ $feed ] );
$uri = array_flip( $uri );
}
return $uri;
}
<?php
defined( 'ABSPATH' ) || die();
add_action( 'wp_rocket_loaded', function() {
remove_filter( 'delete_transient_wc_products_onsale', 'wp_suspend_cache_invalidation' );
});
@Tabrisrp
Tabrisrp / main.js
Created February 1, 2018 15:45
Problematic JS file
// ================================================================================== //
// # Document on Ready
// # Document on Resize
// # Document on Scroll
// # Document on Load
// # Header Settings
@Tabrisrp
Tabrisrp / microdata-markup-google-sitelink-searchbox
Last active July 22, 2018 00:30
ADD microdata markup for Google sitelinks search box in WP search form
add_filter( 'rocket_cache_reject_ua', 'wprocket_remove_fb_ua' );
function wprocket_remove_fb_ua( $ua ) {
if ( in_array( 'facebookexternalhit', $ua ) ) {
$ua = array_flip( $ua );
unset( $ua[ 'facebookexternalhit' ] );
$ua = array_flip( $ua );
}
return $ua;
}
@Tabrisrp
Tabrisrp / rocket-remove-html-expire.php
Created March 15, 2017 20:09
Remove WP Rocket html expire rule
<?php
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
/**
* Remove expiration on HTML to prevent issue with Varnish cache
*
* @author Remy Perona
*
* @param string $rules htaccess rules.
* @return Updated htaccess rules
<?php
function rocket_remove_acs_mandatory_cookies( $cookies ) {
$cookies = array_flip( $cookies );
unset( $cookies['aelia_cs_selected_currency'] );
unset( $cookies['aelia_customer_country' );
return array_flip( $cookies );
}
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_aelia_currencyswitcher_mandatory_cookie', 11 );