From 05deb182e8af210e73dae6b9514e89ccfabde258 Mon Sep 17 00:00:00 2001 From: Dan Head Date: Wed, 24 Jun 2020 19:25:22 +0100 Subject: [PATCH] add description metadata --- theme/functions.php | 17 +++++++++++++++++ theme/header.php | 1 + 2 files changed, 18 insertions(+) diff --git a/theme/functions.php b/theme/functions.php index d84f953..e01b9ec 100644 --- a/theme/functions.php +++ b/theme/functions.php @@ -151,6 +151,23 @@ function windycoys_is_ie() { return false; } +function windycoys_first_sentence($string) { + $sentence = preg_split( '/(\.|!|\?)\s/', $string, 2, PREG_SPLIT_DELIM_CAPTURE ); + return $sentence['0'] . $sentence['1']; +} + +function windycoys_get_description($post_id) { + if (get_post_type() == "post") { + $post = get_post($post_id); + $content = (strlen($post->post_excerpt) === 0) ? + strip_tags(windycoys_first_sentence($post->post_content)) : + $post->post_excerpt; + return $content; + } else { + return get_bloginfo('description'); + } +} + function windycoys_jetpack_custom_image($media, $post_id, $args) { if ($media) { return $media; diff --git a/theme/header.php b/theme/header.php index 3e33519..2f52440 100644 --- a/theme/header.php +++ b/theme/header.php @@ -11,6 +11,7 @@ $manifest = get_template_directory_uri() . '/manifest.json'; <?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' « '; } ?> <?php bloginfo('name'); ?> +