Skip to content

Instantly share code, notes, and snippets.

@wp-seopress
Last active February 9, 2021 17:54
Show Gist options
  • Save wp-seopress/23912a56ca760a42842e9a5026a628c6 to your computer and use it in GitHub Desktop.
Save wp-seopress/23912a56ca760a42842e9a5026a628c6 to your computer and use it in GitHub Desktop.
Automatic meta description for Oxygen Builder
//Oxygen Builder Generate automatic meta description
function sp_titles_template_variables_array($array) {
$array[] = '%%oxygen%%';
return $array;
}
add_filter('seopress_titles_template_variables_array', 'sp_titles_template_variables_array');
function sp_titles_template_replace_array($array) {
if ( is_plugin_active( 'oxygen/functions.php' ) && function_exists( 'ct_template_output' ) && ! isset( $_GET['ct_builder'] ) ) {
add_filter( 'wp_doing_ajax', '__return_true' );
$content = do_shortcode( get_post_meta( get_the_id(), 'ct_builder_shortcodes', true) );
remove_filter( 'wp_doing_ajax', '__return_true' );
$array[] = preg_replace( '/\r|\n/', '', substr( strip_tags( wp_filter_nohtml_kses( $content ) ), 0, 160 ) );
}
return $array;
}
add_filter( 'seopress_titles_template_replace_array', 'sp_titles_template_replace_array' );
////////////////////////////////////////////////////////
//USE THIS SNIPPET ONLY IF THE FIRST ONE DOESN'T WORK
///////////////////////////////////////////////////////
function sp_titles_template_variables_array2($array) {
$array[] = '%%oxygen%%';
return $array;
}
add_filter('seopress_titles_template_variables_array', 'sp_titles_template_variables_array2');
function sp_titles_template_replace_array2($array) {
if (is_plugin_active('oxygen/functions.php') && function_exists('ct_template_output')) {
$array[] = substr(strip_tags(wp_filter_nohtml_kses(ct_template_output())), 0, 160);
}
return $array;
}
add_filter('seopress_titles_template_replace_array', 'sp_titles_template_replace_array2');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment