wp_get_attachment_url()返回附件(特色图像/文件)URL网址

目录

描述

译文

返回附件文件的完整URI,出错则返回false。

原文

Returns a full URI for an attachment file or false on failure.

wp_get_attachment_url() 描述

用法

<?php wp_get_attachment_url$id ); ?>

wp_get_attachment_url() 用法

参数

$id

(integer) (必填) The ID of the desired attachment

默认值: None

wp_get_attachment_url() 参数

示例

Use Post Thumbnail as Background Image

wp_get_attachment_url() 示例

注意

You can change the output of this function through the wp get attachment url 过滤器.

This function will not urlencode the url. If you have attachments with invalid characters in their name, you should rawurlencode the ouput of this function in order to have a valid url.

Sample code that gives you a root relative url to your attachment:

If you want a URI for the attachment page, not the attachment file itself, you can use get_attachment_link.

Also refer:
wp_insert_attachment, wp_upload_dir, wp_get_attachment_image_src

wp_get_attachment_url() 注意

历史

添加于 版本: 2.1.0

wp_get_attachment_url() 历史

源文件

wp_get_attachment_url() 函数的代码位于 wp-includes/post.php.

wp_get_attachment_url() 源文件

相关