Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressでカスタムダッシュボードウィジェットを追加する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressには毎日たくさんの新しいテーマがリリースされているが、どれもこの機能を利用していないようだ。WordPress開発者は、サポート情報をカスタムダッシュボードウィジェットに追加すべきである。この投稿では、WordPressでダッシュボードウィジェットをカスタマイズする方法を紹介する。

このコードをテーマのfunctions.phpファイルまたはサイト固有のプラグインに追加するだけでよい。

add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
 
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;

wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');
}

function custom_dashboard_help() {
echo '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="mailto:yourusername@gmail.com">here</a>. For WordPress Tutorials visit: <a href="https://www.wpbeginner.com" target="_blank">WPBeginner</a></p>';
}

メールを変更し、他の有用な情報を追加することを忘れないでください。

このコードは、クライアントのためにカスタムテーマを作成する際に非常に役立ちます。

結果

Custom dashboard widget in WordPress

この投稿が、WordPressでカスタムダッシュボードウィジェットを追加する方法を学ぶのに役立てば幸いである。WordPressの管理エリアから不要な項目を削除する方法についてのガイドもご覧ください。

この投稿が気に入った場合は、WordPress動画チュートリアルのYouTubeチャンネルを購読してください。Twitterや Facebookでもご覧いただけます。

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

51件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Jef Vermeire says

    Can you add multiple widget of the same type on the wordpress dashboard. For example: can I add the custom ‘custom_help_widget’ twice on my dashboard?

    • WPBeginner Support says

      You could if you wanted to, you would want to add an additional line of the wp_add_dashboard_widget if you wanted it twice :)

      管理者

  3. Xavier Barbot says

    Very useful, thank you, I’ve tried all the plugins but none achieved adding a simple widget for my clients, very slick and easy to replicate by cresting a custom plugin, I give you 5 stars! ;)

    • WPBeginner Support says

      If your custom role can see dashboard widgets, it should be able to see the custom widget.

      管理者

  4. Ron Sierra says

    This was asked once but I could not find the reply or answer. How do I create multiple dashboard widgets?

  5. Bjornen says

    How do I add wp_mail function to this widget?
    Meaning; how do I provide the customer with a contact form in that widget?

  6. Javier says

    Hi, I’m trying to create custom widgets on a per user basis. Each user needs to have a widget with different text in it.

    Is there any way to achieve this?

    • David Guerreiro says

      That is very easy ! With PHP get the current user on the function that you are using for displaying the metabox content and change the HTML depending of the user retreived. Have a look on this :

  7. Nishant says

    i tried to insert a do_shortcode() with shortcode for a contact form to give user a quick access to report any bug of provide feedback but it doesn’t work … any idea how to get CF 7 working with this ?

    Thanks

  8. smayzes says

    Is it possible to do this using OOP?

    e.g.:

    inside a class:

    wp_add_dashboard_widget(‘custom_help_widget’, ‘Help and Support’, array($this, ‘customDashboardHelp’));

    function customDashboardHelp() {

    echo ‘<p>Welcome to your custom CMS!’;

    }

    • Nick Powers says

      I know your message is quite old, but for the sake of others who come here and have the same question. Yes, it does work with OOP, just as you have indicated.

  9. y3kgeek says

    Great idea. What if I want to create a custom dashboard widget that only people with a certain user role, say Contributing Writer, can see?

    • DramaKing says

      I know it’s been three years, but if others happen to come around here looking for an answer (like me), this is how I did it. I don’t know a lot about coding so it’s probably not clean, but this is how I managed to get it to work:

      add_action(‘wp_dashboard_setup’, ‘dashboard_widget_mail’);

      function dashboard_widget_mail() {
      global $wp_meta_boxes;

      if ( current_user_can( ‘delete_users’ ) ) {

      wp_add_dashboard_widget(‘custom_mail_widget’, ‘Widgetname to show up on dashboard’, ‘custom_dashboard_mail’);
      } return true;
      }

      function custom_dashboard_mail() {

      echo ‘Your custom text here.’;
      }

      You can replace ‘delete_users’ for any capability you like of course.

  10. Martin says

    Thx for this! It works great.

    Just a quick question:
    If I want to add 2 or more custom widgets in the functions.php, do I have to change the “action” and “function” name?

  11. ACS04 says

    Sounds good, but should be better to create a simple plugin to do so, in such a way, this widget will be independant from the themes… Don’t you think ?

    • Editorial Staff says

      Well you can, but in our case it contains support information that we want our clients to know. This is mostly for custom theme designs, so it is only good to have when our theme is activated.

      管理者

  12. Daniel says

    Worked like a charm. Using this as a workaround for one of my membership site that locked all dashboard menus; this will point members to the appropriate edit posts links again. :)

    • Editorial Staff says

      Hey Richard, You can make your widget be displayed at the very top using the code in WordPress Codex Dashboard API. We don’t know how to set them side by side without manually going in and saving it for the client. Perhaps sending an email to Jake and asking him would be a good idea.

      Although remember, the settings you set in functions.php does not override the normal settings if the user has previously changed the settings. This only works if the user never organized his/her dashboard before.

      管理者

    • Ash Blue says

      Use display block on the outer most element and float left, make sure to set a width, but that may break it. This is very similar to a gallery layout. This is not suggested and not necessarily how WordPress designed widgets to be used (use at your own risk).

  13. Ash Blue says

    Interesting, I did all of that with the line below. Is one better, or are these both just as good?


    if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
    'name'=>'Contact',
    ));
    }

    • Editorial Staff says

      Your code is for registering Sidebar Widgets. The code we are sharing in this article is to add custom dashboard widget. When one log in to their wp-admin, they see post stats, and other information. This box will be added there.

      Two completely different topics.

      管理者

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。