wordpress特色图片来自外部url,无需下载
我想使用外部图片作为wordpress的特色图片 要么更改worpdress代码。(添加接受url的绑定图像元盒,并进行一些修改,以便正确显示url中的特征图像) 或者修改插件WP remote缩略图,该插件从图像url设置特色图像。它下载图片,在wordpress中创建缩略图,并设置特色图片 修改: *无需从url下载,只需使用url直接显示在博客上即可。 *从wordpress生成的url中删除wp内容/上载以显示特色图像(仅适用于外部url) *没有缩略图创建 非常感谢您的阅读 我知道关于这个问题有很多问题 但如果我们解决了这个问题,它可能会对很多ppl有用 代码如下:wordpress特色图片来自外部url,无需下载,wordpress,image,featured,Wordpress,Image,Featured,我想使用外部图片作为wordpress的特色图片 要么更改worpdress代码。(添加接受url的绑定图像元盒,并进行一些修改,以便正确显示url中的特征图像) 或者修改插件WP remote缩略图,该插件从图像url设置特色图像。它下载图片,在wordpress中创建缩略图,并设置特色图片 修改: *无需从url下载,只需使用url直接显示在博客上即可。 *从wordpress生成的url中删除wp内容/上载以显示特色图像(仅适用于外部url) *没有缩略图创建 非常感谢您的阅读 我知道关于
<?php
/*
Plugin Name: WP Remote Thumbnail
Plugin URI: http://magnigenie.com/wp-remote-thumbnail-set-external-images-featured-image/
Description: A small light weight plugin to set external/remote images as post thumbnail/featured image.
Version: 1.0
Author: Nirmal Kumar Ram
Author URI: http://magnigenie.com
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
?>
<?php
/**
* Initialize wprthumb on the post edit screen.
*/
function init_wprthumb() {
new wprthumb();
}
if ( is_admin() ) {
add_action( 'load-post.php', 'init_wprthumb' );
add_action( 'load-post-new.php', 'init_wprthumb' );
}
class wprthumb {
/**
* Hook into the appropriate actions when the wprthumb is constructed.
*/
public function __construct() {
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
add_action( 'save_post', array( $this, 'save' ) );
}
/**
* Adds the meta box container.
*/
public function add_meta_box( $post_type ) {
if ( post_type_supports( $post_type, 'thumbnail' )) {
add_meta_box(
'some_meta_box_name'
,'Remote Post Thumbnail'
,array( $this, 'render_meta_box_content' )
,$post_type
,'side'
,'default'
);
}
}
/**
* Save the meta when the post is saved.
*/
public function save( $post_id ) {
/*
* We need to verify this came from the our screen and with proper authorization,
* because save_post can be triggered at other times.
*/
// Check if our nonce is set.
if ( ! isset( $_POST['wprthumb_nonce'] ) )
return $post_id;
$nonce = $_POST['wprthumb_nonce'];
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'wprthumb' ) )
return $post_id;
// If this is an autosave, our form has not been submitted,
// so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check the user's permissions.
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
/* All good, its safe for us to save the data now. */
// Sanitize the user input.
$image = sanitize_text_field( $_POST['remote_thumb'] );
$upload_dir = wp_upload_dir();
//Get the remote image and save to uploads directory
$img_name = time().'_'.basename( $image );
$img = wp_remote_get( $image );
$img = wp_remote_retrieve_body( $img );
$fp = fopen( $upload_dir['path'].'/'.$img_name , 'w');
fwrite($fp, $img);
fclose($fp);
$wp_filetype = wp_check_filetype( $image , null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', $image ),
'post_content' => '',
'post_status' => 'inherit'
);
//require for wp_generate_attachment_metadata which generates image related meta-data also creates thumbs
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_id = wp_insert_attachment( $attachment, $image, $post_id );
//Generate post thumbnail of different sizes.
$attach_data = wp_generate_attachment_metadata( $attach_id , $image );
wp_update_attachment_metadata( $attach_id, $attach_data );
//Set as featured image.
delete_post_meta( $post_id, '_thumbnail_id' );
add_post_meta( $post_id , '_thumbnail_id' , $attach_id, true);
}
/**
* Render Meta Box content.
*/
public function render_meta_box_content( $post ) {
// Add an nonce field so we can check for it later.
wp_nonce_field( 'wprthumb', 'wprthumb_nonce' );
// Display the form, using the current value.
echo '<label for="remote_thumb">';
_e( 'Enter remote image url', 'wprthumb' );
echo '</label> ';
echo '<input type="text" id="remote_thumb" name="remote_thumb" size="25" />';
}
}
我刚刚发现,您可以从远程URL插入图像,而无需先下载图像,然后再重新上传。这在Wordpress中默认工作,无需安装任何插件
以下是方法:
无论您在哪里看到上载文件,请单击该按钮-您的文件浏览器将显示在您希望您必须选择本地文件的位置,但如果您只是将图像URL粘贴到此框中,然后单击“打开”或“输入”,Wordpress将从远程URL导入图像
单击“选择文件”从远程URL上载图像
将远程图像URL粘贴到您通常拥有文件名的位置我发现这个插件似乎可以满足您的需要:
您可以使用该插件来实现这一点。对不起,我只是不想在我的服务器上放置任何文件。只需显示远处的图片。谢谢你的提示,我不知道这个。是的,自从我发现它以来,它为我节省了很多时间。你找到了方法吗?我使用的是Nelio外部功能图像。我今天尝试了你的插件,但它似乎无法处理谷歌照片的图像。你能联系支持人员吗?谢谢