Skip Navigation

[Resolved] Unable to Add Custom Icon for Custom Post Type

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Dave 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1224775

I am trying to:

Use my own graphic for the dashboard menu icon of my custom post types.

Link to a page where the issue can be seen:

Not really anywhere to see this at present.

I expected to see:

Menu icon changed to my graphic.

Instead, I got:

Nothing.

I have been trying to change my menu icons, and I know there is a feature request out on this one but having a simple upload field next to the icon button should definitely be implemented.

I have read through the documentation, and it references the visibility field of a CPT, but this is no longer a feature and something that is confusing a lot of people. The current build of Types still references this as well in the help drop down at the top of the screen. Given this, most of the information in the forums is sadly useless.

I have found this thread:

https://toolset.com/forums/topic/ability-to-add-custom-icon/#post-586204

Where code is supplied that seems to make perfect sense. I have modified and implemented it, and apparently it runs without issue, but nothing is changing. My CPT slug is "gift-list" and here is my code:

<?php
/**
 * Change Gift List Icon
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_filter( 'wpcf_type', 'toolset_add_custom_icon', 10, 2 );
 
function toolset_add_custom_icon( $params, $post_type ) {
 
    // adjust to your needs
    $cpt_slug = 'gift-list';
 
     
    if( $post_type != $cpt_slug ) {
        return $params;
    }
 
  $params['menu_icon']=theme_url( "../images/fw-dashboard-logo.png", __FILE__ );
 
    return $params;
 
}
?>

I've added this code in a Toolset custom code snippet and even though I've tried various approaches including simply putting a full url in the $params, but nothing makes any difference. The image file is 16x16 transparent backed png and is stored in the themes image folder.

I may well be missing something obvious, but for the life of me I can't see what and this just feels like it should not be this difficult. I'd really appreciate some help here as I'm going round in circles.

Cheers.

#1224827

Hello,

Please try to move the custom PHP codes to your theme file functions.php, and test again, it works fine in my localhost.

#1225119

Ok, with a few tweeks that does seem to work. For anyone finding this post and wanting to change the icon themselves here is the working code:

/**
 * Change Gift List Icon
 */

add_filter( 'wpcf_type', 'toolset_add_custom_icon', 10, 2 );
 
function toolset_add_custom_icon( $params, $post_type ) {
 
    // adjust to your needs
    $cpt_slug = 'gift-list';
 
     
    if( $post_type != $cpt_slug ) {
        return $params;
    }
 
  $params['menu_icon'] = get_template_directory_uri() . "/images/fw-dashboard-logo.png";
 
    return $params;
 
}

Any ideas why it doesn't work as a Toolset Snippet Luo? I'm assuming it's to do with when the code is run, but that is a guess. It's a shame, cause now I have it attached to the theme its less portable, so I guess I'll turn it into a plugin later, but thanks for the help.

#1225532

For the question:
Any ideas why it doesn't work as a Toolset Snippet

Since the wordpress action hook wpcf_type is triggered before "Custom code snippets" loaded, so it does not work in Toolset Snippet.

#1225882

That's what I thought, cheers for clarifying that for me.

It's working perfectly now and I've modified it to work as an array so I can do as many as I like.

Thanks again.