• I’m new learner of WordPress Plugins development. I was created a admin bar menu for my plugin but I can’t add menu icon.

    $wp_admin_bar->add_menu( array(
    	'id' => 'Visit',
    	'title' => __('<img src="'.get_bloginfo('wpurl').'/icon.png" style="vertical-align:middle;margin-right:5px" alt="Visit Site" title="Visit Site" />Visit Site' ),
    	'href' => get_bloginfo('wpurl')
    ));

    I used this code but the icon didn’t come.

    Anybody can help me ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Hmmm, looks OK. Is icon.png in your root WP folder? Getting the path to resources correct can often be a challenge. It helps to check the page’s source HTML to be sure your code is outputting what you think it should.

    This next bit wouldn’t effect the icon showing, but you’re using the translation function __() wrong. You cannot pass variable arguments to it, the translator cannot locate text to translate if no one can predict what that text is due to the variable. You want to only translate the static “Visit Site” part, like this:
    'title' => '<img src="your-path" blah blah />'.__('Visit Site'),

    Thread Starter AB Siddik

    (@siddiknmh)

    bcworkz thanks for response. I can understand your code but have a small problem here. Actually don’t understand what path I will use here. My file icon.png location:
    wp-content/plugins/abs-portfolio-plugin/img/icon.png

    Now what path I can use here please sagest me .

    Moderator bcworkz

    (@bcworkz)

    Your goal will be for the output src attribute to be the correct full, absolute path: http, domain, everything. Relative paths in WP have never worked well for me. You can get the absolute path to your code page with Function Reference/plugin dir url. Concatenate the ‘img/icon.png’ to that and you should be good to go.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add admin menu icon for new plugin ?’ is closed to new replies.