Reputation: 63
Web Developer.
I want to make my own wordpress plugin, From what I look at add menu page parameters here: https://developer.wordpress.org/reference/functions/add_menu_page/
add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
you can insert icon url inside wordpress admin menu bars.
And, I look at Sassy Social Share Plugin, the code look like this:
$page = add_menu_page( __( 'Sassy Social Share by Heateor', 'sassy-social-share' ), 'Sassy Social Share', 'manage_options', 'heateor-sss-options', array( $this, 'options_page' ), plugins_url( '../images/logo.png', __FILE__ ) );
I did the same, but not working. The image not loaded.
I want to call icon.png in my image folder here: image
This is my code:
add_action("admin_menu", "addMenu");
function addMenu(){
add_menu_page("Example Options", "Example Options", 4, "example-options", "insideMenu", '<img src="../image/icon.png/>"');
}
function insideMenu(){
echo"<br/>";
echo "Hello World";
}
Any help is appreciated, Thank you.
Upvotes: 0
Views: 337
Reputation: 4408
You should use:
add_menu_page('Sassy Social Share by Heateor', 'sassy-social-share', [...], plugins_url('/images/logo.png', __FILE__) );
The file path is relative to the .php file (achan-plugin.php) and you should delete the "../" part. Also you should use FILE instead of FILE.
This works perfectly for me, with the same folder structure (/images/logo.png).
My full code:
// Add the moduleName Label in the Admin Menu with logo & config page
function moduleName_plugin_create_menu()
{
//create new top-level menu
add_menu_page('moduleName Plugin Settings', 'moduleName', 'administrator', __FILE__, 'moduleName_plugin_settings_page' , plugins_url('/images/logo.png', __FILE__) );
}
//Add the Admin config page
function moduleName_plugin_settings_page()
{
include plugin_dir_path(__FILE__). '/views/admin/admin.php';
}
Upvotes: 1