add description metadata

This commit is contained in:
2020-06-24 19:25:22 +01:00
parent c076620755
commit 05deb182e8
2 changed files with 18 additions and 0 deletions

View File

@@ -151,6 +151,23 @@ function windycoys_is_ie() {
return false; 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) { function windycoys_jetpack_custom_image($media, $post_id, $args) {
if ($media) { if ($media) {
return $media; return $media;

View File

@@ -11,6 +11,7 @@ $manifest = get_template_directory_uri() . '/manifest.json';
<head> <head>
<meta charset="<?php bloginfo('charset'); ?>"> <meta charset="<?php bloginfo('charset'); ?>">
<title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' &laquo; '; } ?> <?php bloginfo('name'); ?></title> <title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' &laquo; '; } ?> <?php bloginfo('name'); ?></title>
<meta name="description" content="<?php echo windycoys_get_description(get_the_id()) ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#201f42"> <meta name="theme-color" content="#201f42">
<?php wp_head(); ?> <?php wp_head(); ?>