Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Featured Image External Link from Custom Field in Page
- Plugin URI: n/a
- 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'.
- Version: 1.0 beta
- Author: alchymyth
- Author URI: http://wordpress.org/support/profile/alchymyth
- License: GPL2
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- */
- add_filter('post_thumbnail_html','add_external_link_on_page_post_thumbnail',10);
- function add_external_link_on_page_post_thumbnail( $html ) {
- if( is_page() ) {
- global $post;
- $name = get_post_meta($post->ID, 'ExternalUrl', true);
- if( $name ) {
- $html = '<a href="' . ( $name ) . '" target="_blank" >' . $html . '</a>';
- }
- }
- return $html;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement