Skip to content

Instantly share code, notes, and snippets.

View sybrew's full-sized avatar

Sybre Waaijer sybrew

View GitHub Profile
@sybrew
sybrew / semversorter.js
Last active April 6, 2025 21:56
Semver sorter
/**
* Sorts an array of version objects based on their semantic version numbers, including pre-release versions.
*
* This function parses each version string using a regular expression to extract its numeric, pre-release,
* and build components and then compares them to order the array.
*
* It supports complex version such as (in order) "1.4.9", "1.5.0-alpha", "1.5.0-alpha2", and "1.5.0", ensuring
* that pre-release versions are sorted correctly relative to final releases.
*
* @param {Array<Object>} versions - An array of version objects where each object contains a "version" property of type string.
@sybrew
sybrew / tsf-article-type-filter.php
Created March 11, 2025 00:52
This filter for The SEO Framework (Articles extension) sets the Article Type to "NewsArticle" for 'post', 'web-story', and 'gira' post types.
<?php
// Do not include the PHP opening tag if PHP is already open
// Per email exchange with Renan.
add_filter(
'the_seo_framework_articles_data',
function ( $data ) {
if ( in_array( get_post_type(), [ 'post', 'web-story', 'gira' ], true ) ) {
@sybrew
sybrew / tsf-custom-taxonomy-term-title-and-description-generator.php
Last active February 14, 2025 15:02
Generates a custom title and description for taxonomy terms.
<?php
// Do not include the PHP opening tag if PHP is already open
// Per https://wordpress.org/support/topic/term_title-in-custom-taxonomies-archive-titles/
add_filter(
'the_seo_framework_generated_archive_title_items',
/**
* Filters the generated archive title items.
*
@sybrew
sybrew / tsf-unset-schema-listings-cpt.php
Created January 20, 2025 18:21
Unset Schema for TSF on listings Custom Post Type
<?php
// Do not include the PHP opening tag if PHP is already opened.
add_filter(
'the_seo_framework_meta_generator_pools',
function ( $generator_pools ) {
if ( 'listings' === tsf()->query()->get_post_type_real_id() )
return array_diff( $generator_pools, [ 'Schema' ] );
@sybrew
sybrew / tsf-acf-filter-excerpt.php
Created December 3, 2024 20:22
Filters The SEO Framework's excerpt and replaces it with "excerpt_description" created via Advanced Custom Fields.
<?php
// Don't include the PHP opening tag if PHP is already open.
add_filter( 'the_seo_framework_get_excerpt', 'my_tsf_acf_excerpt', 10, 2 );
/**
* @param string $excerpt The obtained excerpt.
* @param array|null $args The query arguments. Contains 'id', 'tax', 'pta', and 'uid'.
* Is null when the query is auto-determined.
* @return string The overwritten description.
@sybrew
sybrew / tsf-hot-woocommerce-product-title.php
Last active November 22, 2024 06:29
Adjust WooCommerce title for The SEO Framework with "Hot " at the start.
<?php
// Do not include the PHP opening tag if PHP is already opened.
add_filter(
'the_seo_framework_title_from_generation',
function ( $title, $args ) {
$is_product = false;
@sybrew
sybrew / process-tsf-term-html.php
Last active August 8, 2024 16:13
Process HTML for generated term descriptions in The SEO Framework.
<?php
add_filter(
'the_seo_framework_description_excerpt',
function ( $excerpt, $args ) {
if ( ! strlen( $excerpt ) ) return '';
if ( isset( $args ) ) {
$is_term = 'term' === The_SEO_Framework\get_query_type_from_args( $args );
@sybrew
sybrew / epl-tsf-excerpt.php
Created August 6, 2024 17:09
Fetch the property description from Easy Property Listings and use it as a custom description excerpt for The SEO Framework.
<?php
// Don't include the PHP opening tag if PHP is already opened in the script.
add_filter( 'the_seo_framework_description_excerpt', 'my_custom_meta_description_excerpt', 10, 2 );
/**
* @param string $excerpt The excerpt to use.
* @param array|null $args The query arguments. Contains 'id', 'tax', 'pta', and 'uid'.
* Is null when the query is auto-determined.
<?php
/**
* Plugin name: test wp_get_wp_version performance.
*/
if ( ! function_exists( 'wp_get_wp_version' ) ) {
function wp_get_wp_version() {
require ABSPATH . WPINC . '/version.php';
return $wp_version;
@sybrew
sybrew / index.php
Last active June 23, 2024 04:36
TSF snippet ZIP creator.
<?php
$request = strtok( substr_replace( $_SERVER['REQUEST_URI'], '', 0, strlen( dirname( $_SERVER['PHP_SELF'] ) ) ), '.' );
$r_parts = array_values( array_filter( explode( '/', $request ) ) );
if ( empty( $r_parts[0] ) ) {
http_response_code( 400 );
exit;
}