How to add meta tags to customizr child theme
-
Newbie here. I am using Customizr child theme. my site: https://sproutedjourney.com. My problem originates with facebook share link not giving the correct image or description. I have tried WordPress SEO plugin and the changes didn’t take. I don’t understand most people’s posts on here. I have obtained this code for my functions.php `
add_action('wp_head', 'your_seo_function'); function your_seo_function() { echo 'PUT_YOUR_HTML_HERE'; }
but I’m not sure what to put into the HTML for the above and how to change each meta-tag for each post for the image and description.
I have also received this code:
// 'Custom Meta Description' field below post/page editor add_action('admin_menu', 'custom_meta_desc'); add_action('save_post', 'save_custom_meta_desc'); function custom_meta_desc() { add_meta_box('custom_meta_desc', 'Add meta description <small>(if left empty, the first 200 characters of the excerpt will be used)</small>', 'custom_meta_desc_input_function', 'post', 'normal', 'high'); add_meta_box('custom_meta_desc', 'Add meta description <small>(if left empty, the first 200 characters of the excerpt will be used)</small>', 'custom_meta_desc_input_function', 'page', 'normal', 'high'); } function custom_meta_desc_input_function() { global $post; echo '<input type="hidden" name="custom_meta_desc_input_hidden" id="custom_meta_desc_input_hidden" value="'.wp_create_nonce('custom-meta-desc-nonce').'" />'; echo '<input type="text" name="custom_meta_desc_input" id="custom_meta_desc_input" style="width:100%;" value="'.get_post_meta($post->ID,'_custom_meta_desc',true).'" />'; } function save_custom_meta_desc($post_id) { if (!wp_verify_nonce($_POST['custom_meta_desc_input_hidden'], 'custom-meta-desc-nonce')) return $post_id; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; $customMetaDesc = $_POST['custom_meta_desc_input']; update_post_meta($post_id, '_custom_meta_desc', $customMetaDesc); }
and this to add to the header.php
<meta name="description" content="<?php if( is_single() || is_page() ) : $text = get_post_meta($post->ID,'_custom_meta_desc',true); if(!$text) $text = ($post->post_excerpt) ? $post->post_excerpt : substr($post->post_content, 0, 200).'...'; echo esc_attr(strip_tags(apply_filters('get_the_excerpt',$text))); else : /* optional area to program meta descriptions for index and archive pages, etc */ endif; ?>" />
but I’m again not sure what to add to make this work for each post.
I do have this meta-tag for an image but I’m not sure where to put it or how to apply this to all my posts, again…
<meta property="og:image" content="URL OF IMAGE" />
I am pretty lost with this. Please any help would be great, I just need to sort this all out.
- The topic ‘How to add meta tags to customizr child theme’ is closed to new replies.