Skip to content

Instantly share code, notes, and snippets.

@amielucha
amielucha / .htaccess
Created August 9, 2018 11:53
htaccess Expiry Headers
# ----------------------------------------------------------------------
# | Expires headers |
# ----------------------------------------------------------------------
# Serve resources with far-future expires headers.
#
# (!) If you don't control versioning with filename-based
# cache busting, you should consider lowering the cache times
# to something like one week.
#
@amielucha
amielucha / functions.php
Created July 20, 2018 14:33
Display links for WooCommerce Terms and Conditions and WordPress Privacy Policy
<?php
// Get T&C page (requires WC)
if ( function_exists('wc_get_page_id') ) {
$terms_page = wc_get_page_id( 'terms' );
if ( $terms_page > 0 )
echo '<a href="' . get_the_permalink( $terms_page ) . '">' . get_the_title( $terms_page ) . '</a>';
}
if ( function_exists( 'the_privacy_policy_link' ) )
@amielucha
amielucha / actions.php
Last active May 24, 2018 11:57
Lightseek Privacy Policy addon
<?php
/*
* Displays a Privacy Policy link in the footer.
* Requires WP 4.9.6
*/
function lightseek_privacy_policy() {
if ( function_exists( 'the_privacy_policy_link' ) )
the_privacy_policy_link( '<div class="lightseek-pp">', '</div>');
@amielucha
amielucha / actions.php
Created May 3, 2018 14:10
ACF Pro Widget Custom Fields - WordPress action
<?php
// Replace the values below with the field names configured in ACF.
function cs_dynamic_sidebar_params( $params ) {
// bail early if ACF is not active
if (!function_exists('get_field')) return $params;
// get widget vars
$widget_name = $params[0]['widget_name'];
@amielucha
amielucha / wc-login.php
Created May 2, 2018 15:39
WooCommerce Login link action
<?php
function cs_login_link() {
// Bail early if we don't have WC.
if ( !function_exists('wc_get_cart_url') ) return;
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
$myaccount_page_url = $myaccount_page_id ? get_permalink( $myaccount_page_id ) : NULL;
if ( !$myaccount_page_url ) return;
@amielucha
amielucha / font-awesome-wc-cart.php
Created May 2, 2018 15:15
Font Awesome 5 cart with a WooCommerce counter - action
<?php
// Place in an action.
// Requires Font Awesome 5.
function cs_cart_icon() {
// Bail early if we don't have WC.
if ( !function_exists('wc_get_cart_url') ) return;
?>
<a class="cart-contents text-white" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View the shopping cart' ) ?>">
@amielucha
amielucha / breadcrumbs.php
Last active May 2, 2018 16:52
Yoast Breadcrumbs in a Bootstrap-based theme
<?php
function lightseek_breadcrumbs() {
// Don't show breadcrumbs on the homepage.
if ( is_front_page() || !function_exists('yoast_breadcrumb') ) return;
$bread = yoast_breadcrumb('<nav aria-label="breadcrumb" id="breadcrumbs" class="breadcrumb">','</nav>', false);
// Apply Bootstrap classes to the breadcrumbs
$bread = str_replace('class="breadcrumb_last"', 'class="breadcrumb_last breadcrumb-item active"', $bread);
$bread = str_replace('property="v:title"', 'property="v:title" class="breadcrumb-item"', $bread);
@amielucha
amielucha / functions.php
Created April 4, 2018 15:02
WordPress maintenance mode snippet
<?php
/*
* Temporarily block access to the WordPress site.
*/
function my_little_maintenace_mode() {
if ( !current_user_can( 'administrator' ) ) wp_die('Please <a href="' . wp_login_url() . '">log in</a> first.');
}
add_action('get_header', 'my_little_maintenace_mode');
@amielucha
amielucha / wp-cli_recipes.sh
Last active March 6, 2018 15:17
WP CLI Recipes
#
# Menus
#
# Note: Add '--porcelain' flag to output the ID of the added item
# Documentation
wp help menu
# List Menu Locations
@amielucha
amielucha / my-powershell.ps1
Created March 6, 2018 10:27
PowerShell function accepting parameters
# This function passes up to 9 chained params to `wpcli` on docker in the current directory.
# I haven't figured out how to spread an undefined amount of parameters yet...
# Simply call "wp help", "wp post list" etc.
function wp($p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8, $p9) { docker-compose run --rm wpcli $p1 $p2 $p3 $p4 $p5 $p6 $p7 $p8 $p9 }