Created
September 3, 2019 13:17
-
-
Save sybrew/932ec4ce0e79809931b3211f25a00828 to your computer and use it in GitHub Desktop.
Creates a description shortcode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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