• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

WordPress Tips and Tricks

  • Home
  • WordPress Tutorials
  • Useful Links

Meta Description on Pages

Home - SEO - Meta Description on Pages

November 20, 2020 by wptricks

Enable the automatic generation of the meta description on pages in WordPress.

function create_meta_desc() {
     global $post;
 if (!is_page()) { return; }
     $meta = strip_tags($post->post_content);
     $meta = strip_shortcodes($post->post_content);
     //$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
     $meta = str_replace( array("\n", "\r", "\t", "", "
", ""), ' ', $meta );
     $meta = substr($meta, 0, 125);
     echo "
";
 }
 add_action('wp_head', 'create_meta_desc');
Category: SEO, Code Snippets
Previous Post:Find Out Which Host a Website is On
Next Post:Prevent Links in Gravity Forms Paragraph Text Field

Sidebar

Recent Posts

  • Truncate Text with CSS
  • CSS { In Real Life }
  • Prevent Links in Gravity Forms Paragraph Text Field
  • Meta Description on Pages
  • Find Out Which Host a Website is On

Categories

  • Code Snippets
  • Design Resources
  • Fonts
  • SEO
  • Tutorials
  • Uncategorized
  • Useful Links
  • WooCommerce

A Few of Our Favorite Products


Copyright © 2023 · WordPress Tips and Tricks · All Rights Reserved

Back to top