Display custom list of tags in post/page editor with hooks

I used the information posted on this blog post to display specific tags when editing a post. The editors on my site wanted the ability to display pre-specified tags instead of the most popular ones. We have a lot of tags and sometimes the ones they want to use are not being used because they are not seen and they don’t remember what to search for.

So in the wp-admin/includes/ajax-actions.php file I changed the line 651 to

Read More
$tags = get_terms( $taxonomy, array( 
    'number' => 45, 
    'orderby' => 'name', 
    'order' => 'DESC', 
    'include' => array('21', '12') 
) );

where the include array is the selection of tags I want to display.

and line 665 to

$return = wp_generate_tag_cloud( $tags, array(
    'largest' => 10, 
    'smallest' => 10, 
    'filter' => 0, 
    'format' => 'flat', 
    'separator' => "  "
) );

This works fine for displaying a sequential list (I didn’t want a tag cloud) of specific tags but these changes are to the wordpress core and on the next update I’ll have to go in and re-do these. Is there any way to accomplish this with hooks so that I don’t mess with the core?

Thanks

Related posts

1 comment

  1. We can override the Ajax call to wp_ajax_get_tagcloud() and do a clean hack.

    <?php
    /* Plugin Name: Custom Admin Tag Cloud */
    
    add_action( 'wp_ajax_get-tagcloud', 'ajax_tag_cloud_wpse_99497', 1 );
    
    function ajax_tag_cloud_wpse_99497() 
    {
        // PASTE ALL THE MODIFIED FUNCTION HERE
        // http://core.trac.wordpress.org/browser/tags/3.5.1/wp-admin/includes/ajax-actions.php#L639
    }
    

    Restore your core files to its original state, copy the modified function inside the above container and create a plugin for it. And ready to go.

Comments are closed.