Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // og tags
- function fb_opengraph() {
- global $post;
- if(is_single()) {
- if(has_post_thumbnail($post->ID)) {
- $img_src = wp_get_attachment_url(get_post_thumbnail_id($post->ID), 'medium');
- } else {
- $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
- }
- 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 the_field('opis_produktu'); ?>"/>
- <meta property="og:type" content="article"/>
- <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
- <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
- <meta property="og:image" content="<?php echo $img_src; ?>"/>
- <?php
- } else {
- ?>
- <meta property="og:title" content="<?php echo get_bloginfo('title'); ?>"/>
- <meta property="og:description" content="Opis w functions php"/>
- <meta property="og:type" content="article"/>
- <meta property="og:url" content="<?php echo get_home_url(); ?>"/>
- <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
- <meta property="og:image" content="<?php echo get_template_directory_uri() ?>/img/site_image.jpg"/>
- <?php
- }
- }
- add_action('wp_head', 'fb_opengraph', 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement