钩子文档

wp_generate_tag_cloud

💡 云策文档标注

概述

wp_generate_tag_cloud 是一个 WordPress 过滤器,用于修改标签云生成的 HTML 输出或数组。该过滤器仅在 wp_generate_tag_cloud() 函数的 $filter 参数为 true 时生效。

关键要点

  • 过滤器名称:wp_generate_tag_cloud
  • 作用:过滤标签云的输出,可修改 HTML 字符串或数组格式的标签链接
  • 触发条件:当 wp_generate_tag_cloud() 的 $filter 参数为 true 时
  • 参数:$return(输出字符串或数组)、$tags(WP_Term 数组)、$args(参数数组)
  • 相关函数:wp_generate_tag_cloud(),用于生成标签云
  • 引入版本:WordPress 2.3.0

代码示例

return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );

注意事项

  • 参数 $args 包含多个配置选项,如 smallest、largest、unit、number、format、separator、orderby、order、filter、topic_count_text、topic_count_text_callback、topic_count_scale_callback、show_count 等,用于自定义标签云的外观和行为。
  • 过滤器可以用于调整标签云的排序、样式或添加额外内容,但需确保 $filter 参数启用。

📄 原文内容

Filters the generated output of a tag cloud.

Description

The filter is only evaluated if a true value is passed to the $filter argument in wp_generate_tag_cloud() .

See also

Parameters

$returnstring[]|string
String containing the generated HTML tag cloud output or an array of tag links if the 'format' argument equals 'array'.
$tagsWP_Term[]
An array of terms used in the tag cloud.
$argsarray
An array of wp_generate_tag_cloud() arguments.

More Arguments from wp_generate_tag_cloud( … $args )

Array or string of arguments for generating a tag cloud.

  • smallest int
    Smallest font size used to display tags. Paired with the value of $unit, to determine CSS text size unit. Default 8 (pt).
  • largest int
    Largest font size used to display tags. Paired with the value of $unit, to determine CSS text size unit. Default 22 (pt).
  • unit string
    CSS text size unit to use with the $smallest and $largest values. Accepts any valid CSS text size unit. Default 'pt'.
  • number int
    The number of tags to return. Accepts any positive integer or zero to return all.
    Default 0.
  • format string
    Format 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'.
  • separator string
    HTML or text to separate the tags. Default “n” (newline).
  • orderby string
    Value to order tags by. Accepts 'name' or 'count'.
    Default 'name'. The ‘tag_cloud_sort’ filter can also affect how tags are sorted.
  • order string
    How to order the tags. Accepts 'ASC' (ascending), 'DESC' (descending), or 'RAND' (random). Default 'ASC'.
  • filter int|bool
    Whether to enable filtering of the final output via ‘wp_generate_tag_cloud’. Default 1.
  • topic_count_text array
    Nooped plural text from _n_noop() to supply to tag counts. Default null.
  • topic_count_text_callback callable
    Callback used to generate nooped plural text for tag counts based on the count. Default null.
  • topic_count_scale_callback callable
    Callback used to determine the tag count scaling value. Default default_topic_count_scale() .
  • show_count bool|int
    Whether to display the tag counts. Default 0. Accepts 0, 1, or their bool equivalents.

Source

return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );

Changelog

Version Description
2.3.0 Introduced.