Due to location constraints, the Tag Cloud widget settings display 30 tags. Can I insert a custom link at the end of the tag cloud? So that I can link to a tag archive page.
Thanks in advance!
Due to location constraints, the Tag Cloud widget settings display 30 tags. Can I insert a custom link at the end of the tag cloud? So that I can link to a tag archive page.
Thanks in advance!
Yes, you can.
WP_Widget_Tag_Cloud widget uses wp_tag_cloud
to generate the tag cloud. And inside that function and at the end of that function you can find this:
/**
* Filters the tag cloud output.
*
* @since 2.3.0
*
* @param string $return HTML output of the tag cloud.
* @param array $args An array of tag cloud arguments.
*/
$return = apply_filters( 'wp_tag_cloud', $return, $args );
It means, that you can use this filter to append something to the output.
There are only 2 things you have to take care of:
array
and this is not HTML, so you should not append your link in that case.So here’s the code:
add_filter( 'wp_tag_cloud', function ( $return, $args ) {
if ( 'array' != $args['format'] ) {
$return .= '<a href="https://wordpress.stackexchange.com/questions/341805/<YOUR LINK URL>" class="more"><YOUR LINK CAPTION></a>';
}
return $return;
}, 10, 2 );