#36964 closed enhancement (fixed)
Show/hide the tag-cloud on `edit-tags.php` admin pages using a filter
Reported by: | ramiy | Owned by: | helen |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | has-patch |
Focuses: | ui, administration | Cc: |
Description
The edit-tags.php
page shows a tag-cloud with "Popular Tags" on non-hierarchical taxonomies. There is no way to remove this tag cloud and the H2 title from the admin screen.
This ticket introduces a new boolean filter "show_admin_popular_items_tag_cloud
" that allows you to remove this blog-feature.
The current code that shows the tag cloud:
if ( ! is_null( $tax->labels->popular_items ) ) { if ( current_user_can( $tax->cap->edit_terms ) ) { $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) ); } else { $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) ); } if ( $tag_cloud ) : ?> <div class="tagcloud"> <h2><?php echo $tax->labels->popular_items; ?></h2> <?php echo $tag_cloud; unset( $tag_cloud ); ?> </div> <?php endif; }
The new code with the proposed filter:
$show_admin_popular_items = ! is_null( $tax->labels->popular_items ); /** * Filters whether to show the popular items tag cloud in the taxonomy admin screen. * * This filter controls the visibility of the popular items tag cloud in the * taxonomy admin screen. * * By default, the tag cloud is visible on non-hierarchy taxonomies admin pages. * You can hide it using `__return_false`. * * @since 4.6.0 * * @param bool $show_admin_popular_items Whether to show the popular items tag cloud. */ if ( apply_filters( 'show_admin_popular_items_tag_cloud', $show_admin_popular_items ) ) { if ( current_user_can( $tax->cap->edit_terms ) ) { $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) ); } else { $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) ); } if ( $tag_cloud ) { ?> <div class="tagcloud"> <h2><?php echo $tax->labels->popular_items; ?></h2> <?php echo $tag_cloud; unset( $tag_cloud ); ?> </div> <?php } }
Attachments (4)
Change History (30)
#2
follow-up:
↓ 4
@
8 years ago
How useful is that tag cloud anyway? Why not completely remove it instead of adding an option to do so?
#3
@
8 years ago
For some history and context, the tag cloud on the tags screen was added around 2.7 when basic styling of any measurable kind was also added to the screen, see [9339]. At the time, this improvement was pre-list table, pre-edit-tag links, pre-most anything we're familiar with today.
For a bit of fun, you can see the progression:
I would be in favor of at least switching to hiding the tag cloud by default for tags going forward.
#4
in reply to:
↑ 2
@
8 years ago
Replying to swissspidy:
How useful is that tag cloud anyway? Why not completely remove it instead of adding an option to do so?
Removing this "blog-era-feature" sounds good, either by removing it from the code entirely or by filtering the preview.
#7
@
8 years ago
I like the idea. It's very useful for custom taxonomies with other behaviour than tags
#9
@
8 years ago
- Keywords needs-refresh added
- Milestone changed from Awaiting Review to 4.7
@ramiy Sure. Let's refresh the patch for 4.7 and additionally pass $taxonomy
to the filter. Also, we should keep the current style of if/endif
because it wraps markup.
Let's also look at hiding it by default (opposite of current behavior). So rather than assigning the current condition to the filter via a variable, the filter should be in addition to that and the logic reversed, e.g.
<?php $show_admin_popular_items = apply_filters( 'show_admin_popular_items_tag_cloud', false, $taxonomy ); if ( ! is_null( $tax->labels->popular_items ) && true === $$show_admin_popular_items ) {
#10
follow-up:
↓ 11
@
8 years ago
Do we also want to look at display of the popular items in the tags meta box in the post editing screen?
#11
in reply to:
↑ 10
@
8 years ago
Replying to DrewAPicture:
Do we also want to look at display of the popular items in the tags meta box in the post editing screen?
Not in this ticket.
#12
@
8 years ago
@DrewAPicture,
- patch refreshed for 4.7
- $tax object was added as a parameter
- current
if/endif
style is not changed - the tag cloud is now hidden by default (opposite of current behavior)
- phpDocs updated, mentioning the behavior change
#13
@
8 years ago
+1 for removing it entirely. Seems dated and unnecessary if I am editing the tags and I want a particular one I will probably search for it or click for it.
This ticket was mentioned in Slack in #core by ramiy. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by aaroncampbell. View the logs.
8 years ago
#17
@
8 years ago
- Keywords commit added; has-screenshots removed
I like this, especially hidden by default. I tested the patch and it seems to work as expected.
#18
follow-up:
↓ 19
@
8 years ago
I can confirm that the patch applies cleanly and that it functions as advertised. However, I disagree with having a feature in Core that is disabled by default. I'm in favor of either 1.) Reversing the logic, or 2.) Removing the Tag Cloud from Core completely.
#19
in reply to:
↑ 18
@
8 years ago
Replying to stevenkword:
I can confirm that the patch applies cleanly and that it functions as advertised. However, I disagree with having a feature in Core that is disabled by default. I'm in favor of either 1.) Reversing the logic, or 2.) Removing the Tag Cloud from Core completely.
It's not the first time something like this was done the link manager in core was hidden but can be enabled by a single line of code. There are times when this works I don't think this tag clouds adds any real value and should be removed but having it simply not enabled by default works as well.
#20
@
8 years ago
- Keywords commit removed
I agree with @Destac and @stevenkword - if this is to be hidden by default it should be removed entirely.
#21
@
8 years ago
@johnbillion Thanks for fixing that keyword. I meant to loop back to this after @stevenkword and I did the bug scrub, and then travel happened.
Basically, Steven convinced me. I'd prefer to just remove it. We could even drop in a hook there if one doesn't exist that would let people put it back (by actually echoing the title and cloud, not a filter where they just return true).
If we decide we can't remove it, then the current method defaulting to display would be reasonable.
This ticket was mentioned in Slack in #core by helen. View the logs.
8 years ago
#24
@
8 years ago
- Owner set to helen
- Resolution set to fixed
- Status changed from new to closed
In 38735:
#25
@
8 years ago
If someone wants to restore the tag cloud, add_tag_form
action can be used for that:
function wp36964_restore_tag_cloud_on_tags_screen() { global $taxnow, $taxonomy, $post_type; $tax = get_taxonomy( $taxnow ); if ( ! is_null( $tax->labels->popular_items ) ) { if ( current_user_can( $tax->cap->edit_terms ) ) { $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'echo' => false, 'link' => 'edit' ) ); } else { $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) ); } if ( $tag_cloud ) : ?> <div class="tagcloud"> <h2><?php echo $tax->labels->popular_items; ?></h2> <?php echo $tag_cloud; ?> </div> <?php endif; } } add_action( 'add_tag_form', 'wp36964_restore_tag_cloud_on_tags_screen' );
The patch was tested.
You can hide the tag cloud using:
add_filter( 'show_admin_popular_items_tag_cloud', '__return_false' );