Skip to content

Instantly share code, notes, and snippets.

@thekendog
Created September 3, 2024 19:44
Show Gist options
  • Save thekendog/7e6b6d9591e2844437d6b2677db78729 to your computer and use it in GitHub Desktop.
Save thekendog/7e6b6d9591e2844437d6b2677db78729 to your computer and use it in GitHub Desktop.
Set the default meta description in SEOPress if a post/page is built with Bricks
/*
* Set the default meta description in SEOPress if a post/page is built with Bricks
*/
add_filter('seopress_titles_desc', 'seopress_set_bricks_default_description');
function seopress_set_bricks_default_description($description)
{
if (!empty(trim($description))) {
return $description;
}
if (!is_singular()) {
return $description;
}
global $post;
if (Bricks\Helpers::get_editor_mode($post->ID) == 'bricks') {
$bricks_content = get_post_meta($post->ID, BRICKS_DB_PAGE_CONTENT, true);
if ($bricks_content) {
$description = Bricks\Blocks::serialize_bricks_to_blocks($bricks_content, $post->ID);
$description = wp_trim_words(esc_attr(stripslashes_deep(wp_filter_nohtml_kses(wp_strip_all_tags(strip_shortcodes($description), true)))), apply_filters('seopress_excerpt_length', 50));
}
}
return $description;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment