Skip to content

Instantly share code, notes, and snippets.

View sybrew's full-sized avatar

Sybre Waaijer sybrew

View GitHub Profile
@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.
@sybrew
sybrew / acf-tsf-post-and-term-description.php
Last active April 12, 2024 19:03
Gets a custom post and term fields from ACF to override TSF's generated description.
<?php
// Don't include the PHP opening tag if PHP is already open.
// Previous: https://gist.github.com/sybrew/0562fdbc98d7fdc134c2c9ff5bad863b.
// For: https://wordpress.org/support/topic/meta-og-description-for-a-custom-taxonomy-term/
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 / disable-tsf-canonical-url.php
Created March 27, 2024 01:44
Disable canonical URL output of The SEO Framework v5.0 or later.
<?php
// Do not include the PHP opening tag if PHP is already open.
add_filter(
'the_seo_framework_meta_render_data',
function ( $tags_render_data ) {
unset( $tags_render_data['canonical'] );
return $tags_render_data;
},
@sybrew
sybrew / style-separator-tsf-breadcrumbs.php
Created March 20, 2024 23:18
Styles the breadcrumb separator in TSF, by decreasing the separator distances from 1ch to 0.5ch.
<?php
// Don't include the PHP opening tag if PHP is already open.
// From: https://wordpress.org/support/topic/format-space-around-separator-in-breadcrumb/
add_filter(
'the_seo_framework_breadcrumb_shortcode_css',
function ( $css, $class ) {
// Create a reference so we do not have to write the long selector repeatedly.
@sybrew
sybrew / get-primary-term-tsf.php
Created March 20, 2024 22:41
Gets primary term name automatically from any post type for The SEO Framework WordPress plugin.
<?php
// Don't include the PHP opening tag if PHP is already open.
function get_primary_term_name( $post_id ) {
$taxonomies = array_keys( array_filter(
tsf()->taxonomy()->get_hierarchical( 'objects', get_post_type( $post_id ) ),
'is_taxonomy_viewable',
) );
$taxonomy = reset( $taxonomies );
@sybrew
sybrew / remove-tsf-shop-base-breadcrumbs.php
Last active March 20, 2024 21:20
Removes WooCommerce's shop base from The SEO Framework's breadcrumbs.
<?php
// Don't include the PHP opening tag if PHP is already open.
add_filter(
'the_seo_framework_breadcrumb_list',
function ( $list, $args ) {
if ( isset( $args ) ) {
if ( 'single' === \The_SEO_Framework\get_query_type_from_args( $args ) ) {
$is_product = tsf()->query()->is_product( $args['id'] );
@sybrew
sybrew / tsf-robots-if-term.php
Last active March 20, 2024 20:38
Sets noindex if post has term from CPT taxonomy 'partner'.
<?php
// Do not include the PHP opening tag if PHP is already open.
// For: https://wordpress.org/support/topic/no-index-custom-post-type-specific-taxonomy/
// TSF 5.0+
add_filter(
'the_seo_framework_robots_meta_array',
function ( $meta, $args ) {
@sybrew
sybrew / pods-append-tsf-gen-title.php
Created February 21, 2024 17:23
Append brand name from custom pods field to TSF generated title.php
<?php
add_filter(
'the_seo_framework_title_from_generation',
function ( $title, $args ) {
// If Pods is deactivated, skip further processing.
if ( ! function_exists( 'pods_field' ) ) return $title;
if ( null === $args ) {
@sybrew
sybrew / tsf-acf-custom-image-generator.php
Last active February 21, 2024 00:56
Example snippet to prepend image arrays from ACF generators for The SEO Framework.
<?php
// Do not include this PHP opening tag if PHP is already opened...
// Ref: https://theseoframework.com/docs/using-filters/
// Ref: https://wordpress.org/support/topic/featured-image-as-ogimage/
add_filter( 'the_seo_framework_image_generation_params', 'my_tsf_custom_image_generation_args', 10, 2 );
/**
* Adjusts image generation parameters.
*
@sybrew
sybrew / acf-tsf-term-description.php
Last active February 17, 2024 15:19
Gets a custom term field from ACF to override TSF's generated description.
<?php
// Don't include the PHP opening tag if PHP is already open.
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'.
* Is null when the query is auto-determined.
* @return string The overwritten description.