Skip to content

Instantly share code, notes, and snippets.

View benhuson's full-sized avatar

Ben Huson benhuson

View GitHub Profile
@benhuson
benhuson / manage-orphan-menu-items.php
Created September 2, 2015 13:10
Manage WordPress Orphan Menu Items (drop-in)
<?php
class Manage_Orphan_Menu_Items {
function Manage_Orphan_Menu_Items() {
add_action( 'admin_init', array( $this, 'process_menu_item_delete' ) );
add_action( 'admin_menu', array( $this, 'add_admin_page' ) );
}
function add_admin_page() {
@benhuson
benhuson / class-frontend.php
Created February 3, 2012 15:48
WordPress SEO plugin patch
<?php
class WPSEO_Frontend {
function __construct() {
$options = get_wpseo_options();
add_action( 'wp_head', array(&$this, 'head'), 1, 1 );
remove_action( 'wp_head', 'rel_canonical' );
@benhuson
benhuson / attributes-as-options.php
Created August 23, 2022 16:16 — forked from dazecoop/attributes-as-options.php
WooCommerce product attributes as selectable options without variations
<?php
/**
* List available attributes on product page in a drop-down selection
*/
add_action('woocommerce_before_add_to_cart_button', 'list_attributes_on_product_page');
function list_attributes_on_product_page() {
global $product;
$attributes = $product->get_attributes();
@benhuson
benhuson / cust-vimeo-oembed
Last active April 18, 2020 23:30
Customise WordPress Vimeo oEmbed
<?php
/**
* Customise WordPress Vimeo oEmbed
* https://developer.vimeo.com/apis/oembed
*/
function my_oembed_fetch_url( $provider, $url, $args ) {
if ( strpos( $provider, 'vimeo.com' ) !== false) {
@benhuson
benhuson / .htaccess
Created September 14, 2016 11:42
Disable HTTP Strict Transport Security (HSTS) in .htaccess
<IfModule mod_headers.c>
Header set Strict-Transport-Security "max-age=0; includeSubDomains; preload" env=HTTPS
</IfModule>
@benhuson
benhuson / X-Poedit-KeywordsList
Last active June 6, 2019 09:37
WordPress Plugin Language .pot X-Poedit-KeywordsList
__;
_e;
_x:1,2c;
_ex:1,2c;
esc_html__;
esc_html_e;
esc_html_x:1,2c;
esc_attr__;
esc_attr_e;
esc_attr_x:1,2c
@benhuson
benhuson / .htaccess
Created May 22, 2019 10:08
.htaccess block IP behind load balancer
Order Deny,Allow
Deny from all
SetEnvIf X-Forwarded-For "^1\.1\.1\.1" AllowAccess
Allow from env=AllowAccess
@benhuson
benhuson / htaccess-not-ip-redirect.txt
Last active May 15, 2019 01:26
.htaccess rules for redirecting if IP address does not match.
# Redirect other IP addresses
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Single IP Address
RewriteCond %{REMOTE_HOST} !^00.00.00.00
# Multiple IP Addresses
RewriteCond %{REMOTE_HOST} !^(00.00.00.00|00.00.00.00)
RewriteRule .* http://www.example.com/ [R=301,L]
@benhuson
benhuson / how-to-remain-detached.php
Created July 15, 2015 12:19
How to remain detached (when insert a WordPress image into a post)
<?php
/**
* Implement 'wp_ajax_send-attachment-to-editor' to not attach an unattached media item.
*
* In WordPress TRAC 22085 there was a change.
* that caused unattached media files (images) to be attached to posts if they are inserted into the post.
*
* If you don't like this strategy you can disable it using this simple, rather hacky, action hook.
*
@benhuson
benhuson / all-category-post-permalink.php
Last active May 20, 2016 19:01
All Category Post Permalink
<?php
/**
* All Category Post Permalink
*
* When using %category% in permalinks, this allows you to substitute
* an alternative slug "all" to replace the category. By default this
* is not permitted - the post page is force redirected to a URL
* with a valid category.
*/