Skip to content

Instantly share code, notes, and snippets.

@danmaby
Created July 24, 2023 08:52
Show Gist options
  • Save danmaby/c9d4aa3aa844718ecd8ef3ae1e68359b to your computer and use it in GitHub Desktop.
Save danmaby/c9d4aa3aa844718ecd8ef3ae1e68359b to your computer and use it in GitHub Desktop.
A shortcode that displays the SEO description generated by the Filter Everything Pro plugin
/**
* Adds a shortcode that displays the SEO description generated by the Filter Everything Pro
* plugin. If no description is available, the shortcode will display the default content. An
* an optional 'default' attribute can be used to specify the default content.
*
* @param array $atts An array of shortcode attributes.
* @return string The shortcode output.
*/
function ps_add_filters_seo_description_shortcode($atts)
{
// Extract the attributes
$atts = shortcode_atts(
array(
'default' => 'No facets are currently selected.', // Default value if 'default' attribute is not provided
),
$atts,
'fe_seo_description'
);
if (class_exists("FilterEverything\Filter\Container")) {
// Get the SEO description
$description = flrt_get_seo_data('description');
// Check if the description is available
if ($description !== false) {
// Wrap the description in the plugin's HTML and return it
return '<div class="wpc-page-seo-description"><p>' . $description . '</p></div>';
} else {
// Return default content wrapped in the plugin's HTML
return '<div class="wpc-page-seo-description"><p>' . $atts['default'] . '</p></div>';
}
}
}
add_shortcode('fe_seo_description', 'ps_add_filters_seo_description_shortcode');
@wagersantonio
Copy link

wagersantonio commented Nov 16, 2024

Thanks for sharing. I shall use it for my website of motorcycle accident of a celebrity. Hope it will make my site to work smoothly. So that user and search engine love it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment