Search code examples
jquerywordpresstagsadmintag-cloud

WordPress Admin Tag-cloud auto-expand


I need to do a custom WordPress edit product page where the 'Most used tags' list is expanded. I tried to add this in functions.php inside an admin_head function:

jQuery(window).load(function() {
    jQuery(".tagcloud-link").attr( "aria-expanded", "true" );
    jQuery( ".the-tagcloud" ).show();
});

The code runs but the .the-tagcloud element is not visible.

Does anyone have a solution for this?


Solution

  • The problem is that you try to display an element which isn't present in the DOM when you load the page...

    The element ".the-tagcloud" is generated when you click on the link for the first time and not till then just displayed or hidden on every further click!

    But you can simply trigger the click with jquery, I tested the following code and it worked for me:

    function load_custom_wp_admin_style() { ?>
    <script>
        jQuery(window).load(function() {
            jQuery(".tagcloud-link").trigger("click");
        });
    </script>
    <?php }
    add_action( 'admin_footer', 'load_custom_wp_admin_style' );