افزودن یک آیتم به منوی پنل وردپرس
سلام
باید از تابع 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 )
که یک مثال برای اضافه کردن منو مثل زیر هست:
نکته:برای اضافه کردن منو حتما از فانکشن استفاده فرمایید
الان این کد رو به فانکشن قالب یا فایل های اصلی افزونه مدنظرتون اضافه کنید و نتیجه رو ببینید:
function
<code class="php string">ahmadreza_custom_menu_page
() {
<code class="php spaces">
add_menu_page(
<code class="php spaces">
__(
'عنوان دلخواه'
,
'textdomain'
),
<code class="php spaces">
__(
'نام منو'
,
'textdomain'
),
<code class="php spaces">
'manage_options'
,
<code class="php spaces">
'test-menu'
,
<code class="php spaces">
'matne-namayeshi-dar-menu'
,
<code class="php spaces">
''
<code class="php spaces">
);
<code class="php plain">
}
add_action(
'admin_menu'
,
'ahmadreza_custom_menu_page'
);
برای اضافه کردن محتوا به منو:
function
<code class="php string">matne-namayeshi-dar-menu
() {
echo
'متن نمایشی در منو'
;
}
<code class="hljs language-php"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">register_custom_menu_page</span>() </span>{ add_menu_page(<span class="hljs-string">'custom menu title'</span>, <span class="hljs-string">'custom menu'</span>, <span class="hljs-string">'add_users'</span>, <span class="hljs-string">'custompage'</span>, <span class="hljs-string">'_custom_menu_page'</span>, <span class="hljs-literal">null</span>, <span class="hljs-number">6</span>); } add_action(<span class="hljs-string">'admin_menu'</span>, <span class="hljs-string">'register_custom_menu_page'</span>); <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_custom_menu_page</span>()</span>{ <span class="hljs-keyword">echo</span> <span class="hljs-string">"Admin Page Test"</span>; } </code>
لطفا قبل از ارسال پاسخ، این قوانین را مطالعه نمایید:
- به هیچ عنوان از لینک سایتهای دیگر یا لینکهای تبلیغاتی در پاسخ استفاده نکنید.
- تا حد امکان متن پاسخ کامل و واضح باشد.
- محتوای پاسخ را از سایت خود یا سایتی دیگر کپی نکنید.
از آنجا که هدف ما ایجاد یک فضای مفید برای همفکری و رسیدن به پاسخ سوالات است، در صورتی که پاسخ شما یکی از شرایط فوق را نداشته باشد، توسط ناظرین تایید نخواهد شد.