jmlapam

Untitled

Apr 16th, 2014
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: Open Graph FB
  4. Plugin URI: http://www.tweetpress.fr
  5. Description: Les titres et descriptions renseignés dans les champs de All in One SEO en tant que contenus des balises Open Graph (vite fait)
  6. Version: 1.0
  7. Author: Julien Maury
  8. */
  9.  
  10.  
  11. defined('ABSPATH') or die('Cheatin, uh!');
  12.  
  13.  
  14. add_action('wp_head','_jm_og_add_meta');
  15. function _jm_og_add_meta() {
  16.  
  17. global $post;
  18.  
  19. if (class_exists('All_in_One_SEO_Pack')) {
  20.  
  21. $post_id = $post;
  22. if (is_object($post_id)) $post_id = $post_id->ID;
  23. $seo_title = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_title', true)));
  24. $seo_description = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_description', true)));
  25. }
  26.  
  27. ?>
  28. <meta property="fb:admins" content="0000"/>
  29. <?php if (is_single()){ // Si c’est un article
  30. if (has_post_thumbnail()){
  31. $url_thumbnail = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
  32. }
  33. else{
  34. $url_thumbnail = 'Cover-site.jpg';
  35. }
  36.  
  37. ?>
  38.  
  39. <meta property="og:title" content="<?php echo $seo_title; ?>" />
  40. <meta property="og:type" content="article" />
  41. <meta property="og:url" content="<?php echo the_permalink(); ?>" />
  42. <meta property="og:image" content="<?php echo $url_thumbnail; ?>" />
  43. <meta property="og:description" content="<?php echo $seo_description; ?>" />
  44. <?php }
  45.  
  46. else{ // Si ce n’est pas un article (page d’accueil, page, archive, tag…)
  47. $current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  48. ?>
  49. <meta property="og:title" content="<?php echo bloginfo('name'); ?>" />
  50. <meta property="og:type" content="website" />
  51. <meta property="og:url" content="<?php echo $current_url; ?>" />
  52. <meta property="og:image" content="Cover-site.jpg" />
  53. <meta property="og:description" content="<?php echo bloginfo('description'); ?>" />
  54. <?php }
  55. }
RAW Paste Data