Skip to content

Instantly share code, notes, and snippets.

@sybrew
Last active January 11, 2023 06:51
Show Gist options
  • Save sybrew/b0bd829846fc1eda24025eb9f50eb86d to your computer and use it in GitHub Desktop.
Save sybrew/b0bd829846fc1eda24025eb9f50eb86d to your computer and use it in GitHub Desktop.
Filters Advanced Custom Fields (ACF) and The SEO Framework (TSF) description and titles
<?php
/**
* 'the_seo_framework_custom_field_description' of the filter below can be changed with:
* - the_seo_framework_title_from_custom_field
* - the_seo_framework_title_from_generation
* - the_seo_framework_generated_description
* - the_seo_framework_custom_field_description
*
* And many other filters that follow the ( $value, $args ) schema.
* - the_seo_framework_enable_auto_description
* - the_seo_framework_image_details
* - the_seo_framework_image_generation_params
* - the_seo_framework_use_title_branding
* - the_seo_framework_robots_meta_array
*
* Also this one, but the parameter is shifted, see https://gist.github.com/sybrew/8c55f48bb3d8bdff03af0d2ba6271bb4):
* - the_seo_framework_fetched_description_excerpt
*/
add_filter(
'the_seo_framework_custom_field_description',
function( $description, $args ) {
if ( null === $args ) {
// Front-end
if ( is_singular() )
$post_id = tsf()->get_the_real_ID();
} else {
// Custom query, back-end.
if ( empty( $args['pta'] ) && empty( $args['taxonomy'] ) )
$post_id = $args['id'];
}
if ( ! empty( $post_id ) && function_exists( 'get_field' ) )
$custom_field = get_field( 'my_custom_content', $post_id );
if ( ! empty( $custom_field ) )
$description = $custom_field;
return $description;
},
10,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment