Skip to content

Instantly share code, notes, and snippets.

@sybrew
Created September 3, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sybrew/932ec4ce0e79809931b3211f25a00828 to your computer and use it in GitHub Desktop.
Save sybrew/932ec4ce0e79809931b3211f25a00828 to your computer and use it in GitHub Desktop.
Creates a description shortcode.
<?php
// The PHP tag starts PHP. Don't implement it if it's already there.
/**
* Get the current query description: [tsf-description]
* Get another query description, page: [tsf-description id=42]
* Get another query description, term: [tsf-description id=42 taxonomy=category]
*/
add_shortcode( 'tsf-description', function( $atts ) {
if ( ! function_exists( 'the_seo_framework' ) ) return '';
$default_atts = [
'id' => 0,
'taxonomy' => '',
];
$atts = shortcode_atts(
$default_atts,
$atts,
'tsf_description'
);
if ( empty( $atts['id'] ) ) {
$args = null;
} else {
$args = array_filter( array_intersect_key(
$atts,
$default_atts
) ) ?: null;
}
$description = the_seo_framework()->get_description( $args );
return $description;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment