Skip to content

Instantly share code, notes, and snippets.

@amsgator
amsgator / stop-noreferrer.php
Created Sep 7, 2019
Stop WordPress from Adding "noreferrer" to Links
View stop-noreferrer.php
<?php
function my_targeted_link_rel( $rel_values ) {
return 'noopener';
}
add_filter( 'wp_targeted_link_rel', 'my_targeted_link_rel', 999 );
?>
@amsgator
amsgator / vcard.php
Created Jul 9, 2019
Enable vCard Upload in WordPress
View vcard.php
<?php
function enable_vcard_upload( $mime_types ){
$mime_types['vcf'] = 'text/vcard';
$mime_types['vcard'] = 'text/vcard';
return $mime_types;
}
add_filter('upload_mimes', 'enable_vcard_upload' );
?>
@amsgator
amsgator / disable_gutenberg.php
Created Jul 7, 2019
Completely Disable Gutenberg Block Editor
View disable_gutenberg.php
<?php
add_filter('use_block_editor_for_post', '__return_false', 10);
?>
@amsgator
amsgator / .htaccess
Created Jun 24, 2019
Redirect all traffic to naked https in 1 hop
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all http to naked https in 1 hop
RewriteCond %{HTTPS} !on [NC]
RewriteRule ^(.*)$ https://domain\.com/$1 [R=301,L]
# Redirect all https www to naked https in 1 hop
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ https://domain\.com/$1 [R=301,L]
@amsgator
amsgator / .htaccess
Created Jun 24, 2019
Redirect all traffic to https www in 1 hop
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all naked http(s) to https www in 1 hop
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ https://www\.domain\.com/$1 [R=301,L]
# Redirect all http www to https www in 1 hop
RewriteCond %{HTTPS} !on [NC]
RewriteRule ^(.*)$ https://www\.domain\.com/$1 [R=301,L]
View border-box-fix.css
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
@amsgator
amsgator / redirect_attachment_urls.php
Created Apr 7, 2019
Redirect Attachment URLs to the Attachment Itself
View redirect_attachment_urls.php
<?php
function redirect_attachment_urls() {
if ( is_attachment() ) {
wp_redirect( wp_get_attachment_url(), 301 );
exit();
}
}
add_action( 'template_redirect', 'redirect_attachment_urls' );
@amsgator
amsgator / dequeue_woo.php
Created Apr 6, 2019
Dequeue WooCommerce Scripts from Non-WooCommerce Pages / Posts
View dequeue_woo.php
<?php
function dequeue_woo() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() && ! is_account_page() ) {
// Styles
wp_dequeue_style( 'woocommerce-general' );
wp_dequeue_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
// Scripts
@amsgator
amsgator / remove_select2.php
Created Apr 5, 2019
Remove Select2 / SelectWoo from WooCommerce
View remove_select2.php
<?php
function dequeue_select2() {
if ( class_exists( 'woocommerce' ) ) {
// Styles
wp_dequeue_style( 'select2' );
wp_deregister_style( 'select2' );
// Scripts
wp_dequeue_script( 'selectWoo' );
wp_deregister_script( 'selectWoo' );