SHARE
TWEET

aioseop custom

a guest Apr 26th, 2016 16 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wp_get_attachment( $attachment_id ) {
  2.     $attachment = get_post( $attachment_id );
  3.     return array(
  4.         'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
  5.         'caption' => $attachment->post_excerpt,
  6.         'description' => $attachment->post_content,
  7.         'href' => get_permalink( $attachment->ID ),
  8.         'src' => $attachment->guid,
  9.         'title' => $attachment->post_title
  10.     );
  11. }
  12.  
  13. function aioseop_change_canonical($url) {
  14.     global $wp_query;
  15.     $new_url=$url;
  16.     $permlink=get_permalink();
  17.     if (isset($wp_query->query_vars['image'])) {
  18.         $imgvar = trim(explode('/', $wp_query->query_vars['image'])[0]);
  19.         $attachment_meta = wp_get_attachment($imgvar);
  20.         $new_url= $permlink . 'images/' . $imgvar . '/' . toAscii($attachment_meta['title']);
  21.     }
  22.     return $new_url;
  23. }
  24.  
  25. function aioseop_change_title($title) {
  26.     global $wp_query;
  27.     $new_title=$title;
  28.     if (isset($wp_query->query_vars['image'])) {
  29.         $imgvar = trim(explode('/', $wp_query->query_vars['image'])[0]);
  30.         $attachment_meta = wp_get_attachment($imgvar);
  31.         $new_title = $attachment_meta['title'];
  32.     }
  33.     return $new_title;
  34. }
  35.  
  36. function aioseop_change_description($description) {
  37.     global $wp_query;
  38.     $new_description = $description;
  39.     if (isset($wp_query->query_vars['image'])) {
  40.         $imgvar = trim(explode('/', $wp_query->query_vars['image'])[0]);
  41.         $attachment_meta = wp_get_attachment($imgvar);
  42.         $new_description = strip_tags($attachment_meta['caption']);
  43.     }
  44.     return $new_description;
  45. }
  46.  
  47. add_filter('aioseop_canonical_url', 'aioseop_change_canonical' );
  48. add_filter('aioseop_title', 'aioseop_change_title' );
  49. add_filter('aioseop_description', 'aioseop_change_description' );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top