Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Open graph
- https://www.elegantthemes.com/blog/tips-tricks/how-to-add-open-graph-tags-to-wordpress
- http://stackoverflow.com/a/14359678
- http://wordpress.stackexchange.com/a/141136
- http://telegram.me/webpagebot
- */
- function t_opengraph() {
- global $post;
- $post_thumbnail_id = get_post_thumbnail_id($post->ID);
- $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
- if(is_single()) {
- if($excerpt = $post->post_excerpt) {
- $excerpt = strip_tags($post->post_excerpt);
- $excerpt = str_replace("", "'", $excerpt);
- } else {
- $excerpt = get_bloginfo('description');
- }
- ?>
- <meta property="og:title" content="<?php echo the_title(); ?>"/>
- <meta property="og:description" content="<?php echo $excerpt; ?>"/>
- <meta property="og:image" content="<?php echo $post_thumbnail_url; ?>"/>
- <?php
- } else {
- return;
- }
- }
- add_action('wp_head', 't_opengraph', 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement