Skip to content

Instantly share code, notes, and snippets.

View bdeleasa's full-sized avatar

Brianna Deleasa bdeleasa

View GitHub Profile
@bdeleasa
bdeleasa / wp-elementor-overlay-wcag.php
Created June 5, 2023 17:31
Adjust the .elementor-background-overlay element with a PHP filter to add the role="img" attribute for accessibility purposes.
<?php
add_filter( 'elementor/frontend/the_content', 'MYPREFIX_add_role_to_elementor_overlay' );
/**
* Find the <div class="elementor-background-overlay"></div> element and add the role="img" attribute
* to meet accessibility guidelines.
*
* @since 1.0.0
*
* @param $content
* @return string
@bdeleasa
bdeleasa / convert-num-to-abbrev.php
Last active September 1, 2022 14:00
PHP function to convert a given number to a shorthand version. Ex: convert $1,000,000 to $1M
<?php
if ( ! function_exists( 'PREFIX_abbreviate_num' ) ) {
/**
* Converts the given number to an abbreviated version of it and returns that value.
*
* Ex: PREFIX_abbreviate_num( 100000 ) would output 100K.
*
* @since 1.0.0
*
* @param $num int
@bdeleasa
bdeleasa / wordpress-db-get-autoload-size.sql
Created June 28, 2022 20:49 — forked from yanknudtskov/wordpress-db-get-autoload-size.sql
This will show you the autoloaded data size, how many entries are in the table, and the first 10 entries by size. #optimization #database #mysql
SELECT 'autoloaded data in KiB' as name, ROUND(SUM(LENGTH(option_value))/ 1024) as value FROM wp_options WHERE autoload='yes'
UNION
SELECT 'autoloaded data count', count(*) FROM wp_options WHERE autoload='yes'
UNION
(SELECT option_name, length(option_value) FROM wp_options WHERE autoload='yes' ORDER BY length(option_value) DESC LIMIT 10)
@bdeleasa
bdeleasa / wp-fix-pagination-page-1-deadlinks.php
Created April 29, 2022 17:42
A simple filter to fix any and all pagination using paginate_links so /page/1/ is stripped from the first item URL.
@bdeleasa
bdeleasa / get_youtube_id_from_url.js
Created June 12, 2020 19:00
Javascript function that returns the YouTube ID when given a YouTube video URL.
/**
* Function that returns the YouTube ID when given the YouTube URL.
*
* @param url string
* @return int|null
*/
function get_youtube_id_from_url(url) {
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
const match = url.match(regExp);
@bdeleasa
bdeleasa / wp-limit-search-results.php
Created December 19, 2019 18:52
Limits Wordpress search results to only the 'post' post type.
<?php
/**
* @file wp-limit-search-results.php
*
* Limits the website search results to just searching posts.
*
* @package wplsr
* @since 1.0.0
*/
@bdeleasa
bdeleasa / wp-html-buffer.php
Created November 6, 2019 15:12
Meant to be used as a Wordpress MU plugin. Uses output buffering to add a new filter that parses the entire final HTML output of each page.
<?php
/**
* Plugin Name: WP HTML Buffer
* Description: Uses output buffering to add a new filter that parses the entire final HTML output of each page.
* Plugin URI: https://briannadeleasa.com
* Version: 1.0.0
* Author: Brianna Deleasa
* Author URI: https://briannadeleasa.com
* Text Domain: wp-html-buffer
*/
@bdeleasa
bdeleasa / the-events-calendar-menu-items.php
Created October 29, 2019 18:17
Removes any 'Events' menu items if there aren't any upcoming events. Meant to be used with The Events Calendar plugin.
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://briannadeleasa.com
@bdeleasa
bdeleasa / autoptimize-clear-cache.php
Created October 29, 2018 13:13
Simple Wordpress plugin that checks the Autoptimize plugin's cache every 6 hours and clears the cache if it's above a maximum size specified.
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://example.com
@bdeleasa
bdeleasa / the-events-calendar-disable-json.php
Created September 28, 2018 13:42
Disables the default JSON outputted by the Events Calendar plugin.
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://briannadeleasa.com