Advertisement
Guest User

featured image external link

a guest
Jan 28th, 2014
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Featured Image External Link from Custom Field in Page
  4. Plugin URI: n/a
  5. Description: adds an external link to the 'featured image' in a static page; link url has to be in custom field with the key 'ExternalUrl'.
  6. Version: 1.0 beta
  7. Author: alchymyth
  8. Author URI: http://wordpress.org/support/profile/alchymyth
  9. License: GPL2
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License, version 2, as
  13. published by the Free Software Foundation.
  14.  
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19.  
  20. */
  21.  
  22. add_filter('post_thumbnail_html','add_external_link_on_page_post_thumbnail',10);
  23.  
  24. function add_external_link_on_page_post_thumbnail( $html ) {
  25. if( is_page() ) {
  26. global $post;
  27. $name = get_post_meta($post->ID, 'ExternalUrl', true);
  28. if( $name ) {
  29. $html = '<a href="' . ( $name ) . '" target="_blank" >' . $html . '</a>';
  30. }
  31. }
  32. return $html;
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement