How to add Meta Description in pages with Divi Builder and Yoast Seo Plugin without use %%excerpt%% variable?
Just copy below Function and Add a Function in your Divi child theme function.php file.
<?php add_filter( 'wpseo_metadesc', 'sm_divi_builder_content_wpseo_metadesc', 10, 1 ); function sm_divi_builder_content_wpseo_metadesc( $desc ) { // Get $post if you're inside a function global $post; $post_type = get_post_type( $post ); if ($post_type == "page") { //get_meta_description $desc = get_post_meta($post->ID, '_yoast_wpseo_metadesc', true); if($desc=="") { if ( has_excerpt( $post->ID ) ) { // This post has excerpt $desc = $post->post_excerpt; } else { // This post has no excerpt $desc = trim(strip_tags(preg_replace('/\[\/?et_pb.*?\]/', '', $post->post_content))); $desc = substr($desc,0,155); } } } return $desc; } ?>
Recent Comments