Skip to content

Instantly share code, notes, and snippets.

View laurelstreng's full-sized avatar

Laurel laurelstreng

View GitHub Profile
@laurelstreng
laurelstreng / pseudo-alt-text.css
Created March 6, 2025 15:18
Add alternative text to pseudo elements
/**
* Adding alternative text for screen readers to pseudo elements.
*
* https://developer.mozilla.org/en-US/docs/Web/CSS/content#adding_an_image_with_alternative_text
**/
.location {
&::before {
/* fallback content */
content: url(images/backgrounds/location.svg) ' - Alt text is not supported';
@laurelstreng
laurelstreng / style.css
Created December 9, 2024 12:56
CSS – Dark Mode
/**
* CSS Dark Mode
*
* Declare color-scheme: light dark in the :root.
* Then use the light-dark() function to set both colors.
**/
:root {
color-scheme: light dark;
--bg-color: light-dark(white, black);
@laurelstreng
laurelstreng / functions.php
Last active September 3, 2020 15:50
Function to update all Gravity Forms 'State' dropdown field from full state name values to abbreviated state values.
<?php
/**
* Function to update all Gravity Forms 'State' dropdown field (based on field id #6), from full state name values to abbreviated state values if logged into the site.
* Use once, then remove the code.
*/
function lstreng_update_all_gravity_forms() {
// only load for admin panel
if ( is_admin() ) {
// load all forms
$forms = GFAPI::get_forms();
@laurelstreng
laurelstreng / functions.php
Last active July 22, 2020 14:11
If using the Wordpress author template to show user posts, change the main query via the pre_get_posts filter hook to show all types of posts by the author.
<?php
function lstreng_author_any_post_types $query ) {
// apply changes only for author archive page
if ( ! is_author() || ! $query->is_main_query() )
return;
$query->set('post_type', 'any');
}
add_action( 'pre_get_posts', 'lstreng_author_any_post_types' );
@laurelstreng
laurelstreng / deactivate-plugins.php
Created June 1, 2020 15:19
Wordpress mu-plugin to deactivate specific plugins on your local environment if defined in a wp-config-local.php file.
<?php
/*
Plugin Name: Deactivate Plugins Locally
Description: Deactivate specific plugins on your local environment if defined in a wp-config-local.php file.
Version: 1.0
*/
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
if ( defined( 'LOCAL_DISABLED_PLUGINS' ) ) { // If defined in wp-config-local.php
$plugins_to_disable = unserialize( LOCAL_DISABLED_PLUGINS );
@laurelstreng
laurelstreng / wordpress-query--postID-metaValue.php
Last active May 13, 2020 15:11
How to get Post ID by Meta Value
<?php
// Example: Query to show pages that have a meta_value that contains a string (not exact)
// https://rudrastyh.com/wordpress/meta_query.html
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'value' => '[contact-form-7 id="13127" title="Alliance',
'compare' => 'LIKE'
)
@laurelstreng
laurelstreng / .htaccess
Created May 14, 2019 12:40
Retrieve images from Production if not found locally
# Retrieve images from Production if not found locally
RewriteCond %{REQUEST_URI} ^/path/to/files/[^\/]*/?.*$
RewriteCond %{HTTP_HOST} !^www\.your-domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ https://www.your-domain.com/$1 [QSA,L]
@laurelstreng
laurelstreng / MODULE_user.module
Created May 3, 2019 16:26
Drupal 8 Address Field – Reorder subfields in an Address field
// Form alter for the User Registration form
function MODULE_user_form_user_register_form_alter(&$form) {
if (isset($form['field_address'])) {
$form['field_address']['widget'][0]['address']['#after_build'][] = 'wrf_user_address_after_build';
}
}
// Custom function for #after_build
function MODULE_user_address_after_build($element, FormStateInterface $form_state) {
// Move the country field to the bottom
@laurelstreng
laurelstreng / woocommerce-functions.php
Created November 2, 2017 12:47
Woocommerce remove items from sorting dropdown
/**
* Woocommerce Sorting Dropdown
* @param $orderby
* @return mixed
*
* Remove items from sorting dropdown
*/
function ls_woocommerce_catalog_orderby( $orderby ) {
// We still need to add the functionality that actually does the sorting
$orderby['oldest_to_recent'] = __( 'Sort by date: oldest to newest', 'woocommerce' );
@laurelstreng
laurelstreng / woocommerce-functions.php
Created November 2, 2017 12:43
Woocommerce changing "Default Sorting" to "Recommended sorting" on shop and product settings pages sorting dropdown
/**
* Woocommerce Sorting Dropdown
* @param $catalog_orderby
* @return mixed
*
* Changing "Default Sorting" to "Recommended sorting" on shop and product settings pages
*/
function ls_update_sorting_name( $catalog_orderby ) {
$catalog_orderby = str_replace("Default sorting", "Recommended sorting", $catalog_orderby);
return $catalog_orderby;