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!
Share Improve this question edited Jun 30, 2019 at 9:24 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jun 30, 2019 at 9:06 MatthewMatthew 1515 bronze badges1 Answer
Reset to default 1Yes, 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:
- Check the format of the result, before appending your HTML. One of the formats is
array
and this is not HTML, so you should not append your link in that case. - Make sure you modify only the proper cloud (which is not a real problem, because most probably you will have only one tag cloud on your site or you will want to modify all of them just to be consistent).
So here's the code:
add_filter( 'wp_tag_cloud', function ( $return, $args ) {
if ( 'array' != $args['format'] ) {
$return .= '<a href="<YOUR LINK URL>" class="more"><YOUR LINK CAPTION></a>';
}
return $return;
}, 10, 2 );