wp_tag_cloud
云策文档标注
概述
wp_tag_cloud 过滤器用于修改标签云的最终输出HTML,允许开发者自定义显示内容。它接收标签云字符串或数组以及参数数组作为输入,返回过滤后的输出。
关键要点
- 过滤器名称为 'wp_tag_cloud',通过 apply_filters 调用,用于过滤标签云的输出内容。
- 参数包括 $return(标签云字符串或数组)和 $args(参数数组),后者包含 smallest、largest、unit、number、format 等选项。
- 此过滤器仅作用于生成后的HTML输出,不用于修改生成前的参数;参数修改应使用其他相关过滤器。
代码示例
add_filter( 'wp_tag_cloud', 'wpdocs_no_follow_tag_cloud_links' );
function wpdocs_no_follow_tag_cloud_links( $return ) {
$return = str_replace('注意事项
- 过滤器自 WordPress 2.3.0 版本引入,主要用于输出阶段,确保在修改时不影响参数生成逻辑。
- 参数 $args 中的 format 选项决定 $return 的类型(字符串或数组),需根据此调整处理方式。
原文内容
Filters the tag cloud output.
Parameters
$returnstring|string[]-
Tag cloud as a string or an array, depending on
'format'argument. $argsarray-
An array of tag cloud arguments. See wp_tag_cloud() for information on accepted arguments.
More Arguments from wp_tag_cloud( … $args )
Array or string of arguments for generating a tag cloud.
smallestintSmallest font size used to display tags. Paired with the value of$unit, to determine CSS text size unit. Default 8 (pt).largestintLargest font size used to display tags. Paired with the value of$unit, to determine CSS text size unit. Default 22 (pt).unitstringCSS text size unit to use with the$smallestand$largestvalues. Accepts any valid CSS text size unit. Default'pt'.numberintThe number of tags to return. Accepts any positive integer or zero to return all.
Default 0.formatstringFormat to display the tag cloud in. Accepts'flat'(tags separated with spaces),'list'(tags displayed in an unordered list), or'array'(returns an array).
Default'flat'.separatorstringHTML or text to separate the tags. Default “n” (newline).orderbystringValue to order tags by. Accepts'name'or'count'.
Default'name'. The ‘tag_cloud_sort’ filter can also affect how tags are sorted.orderstringHow to order the tags. Accepts'ASC'(ascending),'DESC'(descending), or'RAND'(random). Default'ASC'.filterint|boolWhether to enable filtering of the final output via ‘wp_generate_tag_cloud’. Default 1.topic_count_textarrayNooped plural text from _n_noop() to supply to tag counts. Default null.topic_count_text_callbackcallableCallback used to generate nooped plural text for tag counts based on the count. Default null.topic_count_scale_callbackcallableCallback used to determine the tag count scaling value. Default default_topic_count_scale() .show_countbool|intWhether to display the tag counts. Default 0. Accepts 0, 1, or their bool equivalents.
Source
$return = apply_filters( 'wp_tag_cloud', $return, $args );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
Skip to note 3 content
tarhe
Basic Example
Adds
rel="nofollow"to all the tag cloud links.add_filter( 'wp_tag_cloud', 'wpdocs_no_follow_tag_cloud_links' ); function wpdocs_no_follow_tag_cloud_links( $return ) { $return = str_replace('<a ', '<a rel="nofollow" ', $return ); return $return; }Skip to note 4 content
buddhabackpacker
This “filter” only returns the HTML after generated. There is no longer a filter for the args before generating.