Skip to content

Instantly share code, notes, and snippets.

View audrasjb's full-sized avatar

Jb Audras audrasjb

View GitHub Profile
@audrasjb
audrasjb / jba-force-language-attribute.php
Last active November 23, 2022 18:04
Force fr-CH language attribute on the HTML tag. Made for Jeff Legras (question asked in WordPress Academy Facebook group)
<?php
/**
* Plugin Name: Filter language attribute to force fr-CH.
* Author: Jb Audras
* Author URI: https://jeanbaptisteaudras.com
* License: GPLv2 or later
* Version: 1.0.0
*/
function jba_language_attributes() {
@audrasjb
audrasjb / gf-available-entries
Last active December 20, 2024 10:19
Gravity Forms: Retrieves how much available entries are available for a given form
<?php
/**
* Retrieves how much available entries are available for a given form.
*
* @param int|false $form_id The ID of the form.
*/
function jba_display_available_seats( $form_id = false ) {
if ( ! $form_id ) { return; }
$form = GFAPI::get_form( $form_id );
@audrasjb
audrasjb / contextual_body_classes.php
Last active December 23, 2024 05:11
Contextual body classes to help identify browsers and devices types within WordPress front-end
<?php
/**
* Adds <body> custom classes relative to browsers and device types.
*
* Note: These classes are obtained via WordPress Core Globals and via the wp_is_mobile
* function which both rely on the user agent. wp_is_mobile() is obviously NOT a substitute
* to CSS media queries, but may be used for device specific features or debugging.
*
* @see https://developer.wordpress.org/apis/global-variables/#browser-detection-booleans
* @see https://developer.wordpress.org/reference/functions/wp_is_mobile/
/**
* Filters the_content to automatically add unique ID to headings.
*
* Note: Change the regex to modify the related heading levels.
* Defaults to levels 2 and 3.
*/
function who_automatic_heading_ids( $content ) {
$pattern = "~<h(2|3)[^>]*>(.*?)</h(2|3)>~";
$content = preg_replace_callback( $pattern, function ( $matches ) {
$title = $matches[2];
@audrasjb
audrasjb / accessible-external-links.php
Last active January 14, 2025 08:14
Filters blocks to automatically add aria-label to links that open in a new tab.
@audrasjb
audrasjb / wp-playground-opquast-widget
Last active January 16, 2025 09:00
WordPress Playground instance for Opquast widget
{
"landingPage": "/wp-admin/",
"login": true,
"plugins": [
"https://jeanbaptisteaudras.com/plugins/who-opquast-widgets.zip"
],
"siteOptions": {
"blogname": "Le joli widget Opquast"
}
}
@audrasjb
audrasjb / jba-remove-default-theme-patterns.php
Last active January 16, 2025 18:12
Remove default theme patterns
<?php
/**
* Plugin Name: Remove default theme patterns.
* Author: Jb Audras
* Version: 0.1
* Author URI: https://whodunit.fr
*/
/**
* Unregisters default patterns from TT5.
@audrasjb
audrasjb / jba-yoast-reading-time.php
Last active January 20, 2025 11:31
Add Yoast reading time post meta before posts content
<?php
/**
* Plugin Name: Add Yoast reading time post meta before posts content.
* Author: Jb Audras
* Version: 0.1
* Author URI: https://whodunit.fr
*/
/**
* Gets Yoast reading time and add it before the content.
@audrasjb
audrasjb / playground-blueprint-yoast-reading-time.json
Last active January 20, 2025 20:31
Playground snippet to run Yoast reading time custom function
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"meta": {
"title": "Yoast reading time post meta",
"description": "Add Yoast reading time post meta before posts content",
"author": "audrasjb",
},
"steps": [
{
"step": "installPlugin",
@audrasjb
audrasjb / testing-white-admin-scheme.json
Last active January 20, 2025 23:13
WP Playground Test White Background Admin Scheme
{
"landingPage": "/wp-admin/",
"login": true,
"plugins": [
"https://jeanbaptisteaudras.com/playground/2025-core-admin-colors.zip"
],
"siteOptions": {
"blogname": "White Admin Scheme"
}
}