Skip to content

Instantly share code, notes, and snippets.

View sybrew's full-sized avatar

Sybre Waaijer sybrew

View GitHub Profile
@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;
}
<?php
// Don't include the PHP opening tag if PHP is already open.
// Previous: https://gist.github.com/sybrew/299ad19597f974c89b1564316297c1ed
// For: https://wordpress.org/support/topic/fetch-meta-description-on-custom-field-from-meta-box/
add_filter( 'the_seo_framework_generated_description', 'my_tsf_generated_description', 10, 2 );
/**
* @param string $desc The generated description.
* @param array|null $args The query arguments. Contains 'id', 'tax', 'pta', and 'uid'.
@sybrew
sybrew / set-tsf-taxonomy-title-parts.php
Created April 16, 2024 23:21
Sets TSF taxonomy title parts for taxonomy 'module'.
<?php
// Do not include the PHP opening tag if PHP is already open.
// For request: https://wordpress.org/support/topic/way-to-automatically-create-custom-meta-titles/
add_filter(
'the_seo_framework_generated_archive_title_items',
/**
* @param String[title,prefix,title_without_prefix] $items The generated archive title items.
* @param \WP_Term|\WP_User|\WP_Post_Type|null $object The archive object.