Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
helgatheviking / shortcodes.php
Last active October 11, 2022 21:46
WooCommerce display a single product add to cart form with [add_to_cart_form]
/**
* NB: updated version available here: https://github.com/helgatheviking/add-to-cart-form-shortcode
*/
/**
* Add [add_to_cart_form] shortcode that display a single product add to cart form
* Supports id and sku attributes [add_to_cart_form id=99] or [add_to_cart_form sku=123ABC]
* Essentially a duplicate of the [product_page]
* but replacing wc_get_template_part( 'content', 'single-product' ); with woocommerce_template_single_add_to_cart()
*
@retgef
retgef / wordpress-remove-404-attachments
Created October 20, 2012 03:09
Remove attachment rows where the associated file on the disk doesn't exist.
<?php
/**
* Usage when logged in: http://yourdomain.com/wp-admin/remove-404-attachments=secretpassword
*/
# Hook late into admin_init
add_action('admin_init', 'remove_404_attachments', 9999999);
function remove_404_attachments(){