钩子文档

content_url

💡 云策文档标注

概述

content_url 是一个 WordPress 过滤器,用于修改内容目录的 URL。它允许开发者在运行时动态调整指向内容目录的完整 URL。

关键要点

  • 过滤器名称:content_url
  • 参数:$url(完整 URL,包括协议和路径)和 $path(相对于内容目录的路径,可选)
  • 用途:过滤内容目录的 URL,常用于插件或主题开发中自定义内容路径

代码示例

add_filter('content_url', function($url, $path) {
    // 自定义逻辑,例如添加 CDN 前缀
    return 'https://cdn.example.com' . $url . $path;
}, 10, 2);

注意事项

  • 此过滤器在 WordPress 2.8.0 版本中引入
  • 与 content_url() 函数相关,该函数用于检索内容目录的 URL
  • 使用时需确保正确处理 $path 参数,以避免 URL 拼接错误

📄 原文内容

Filters the URL to the content directory.

Parameters

$urlstring
The complete URL to the content directory including scheme and path.
$pathstring
Path relative to the URL to the content directory. Blank string if no path is specified.

Source

return apply_filters( 'content_url', $url, $path );

Changelog

Version Description
2.8.0 Introduced.