Family Encyclopedia >> Electronics

How to add custom shortcut links to the WordPress toolbar

By default, WordPress displays a toolbar at the top of all pages for registered users. You can take control of the WordPress admin bar, disable it when viewing the site, or even disable it for all users except admins. However, this toolbar can be used in many ways, especially if you run a busy website with multiple authors. In this article, we will show you how to add custom shortcut links to the WordPress toolbar.

Why or when do you need to add custom shortcut links to the WordPress toolbar?

By default, the toolbar displays helpful links to the WordPress admin screens, allowing users to quickly access different sections of your website.

However, they all have links that they visit a lot when they write posts or work on their site. For example, links to an external resource, service or website. These links can be added to the WordPress toolbar as custom shortcut links allowing you and your users to easily access those locations directly from your site or admin area.

Add a custom shortcut link to the WordPress toolbar

To add a custom shortcut link to the WordPress toolbar, you need to simply copy and paste the following code into your theme's functions.php file or a site-specific plugin.

 // agregar un enlace a la función de la barra de herramientas de WP custom_toolbar_link ($ wp_admin_bar) $ args = array ('id' => 'wpbeginner', 'title' => 'Search WPBeginner', 'href' => 'https: // www.google.com:443/cse/publicurl?cx=014650714884974928014:oga60h37xim ',' meta '=> array (' class '=>' wpbeginner ',' title '=>' Search WPBeginner Tutorials ')); $ wp_admin_bar-> add_node ($ args); add_action ('admin_bar_menu', 'custom_toolbar_link', 999); 

This sample code adds a link to a custom Google search engine, which can be used to search for WordPress tutorials on WPBeginner. It uses the add_node function with the arguments described in the array. You need to replace the id, title, href and meta elements with values ​​for your own custom link.

How to add custom shortcut links to the WordPress toolbar

How to add a custom link group to the toolbar

We showed you how to add a custom link to the toolbar, but what if you want to add multiple links and create a custom menu with some shortcuts of your own? To do so, you can group multiple shortcuts into one main item. Child nodes below the parent link will appear when a user hovers over the parent link. This is an example of how to add a custom link group to the WordPress toolbar.

 / * * agregar un grupo de enlaces bajo un enlace principal * / // Agregar una función de enlace de acceso directo principal custom_toolbar_link ($ wp_admin_bar) $ args = array ('id' => 'wpbeginner', 'title' => 'WPBeginner' , 'href' => 'https://www.wpbeginner.com', 'meta' => array ('class' => 'wpbeginner', 'title' => 'Visit WPBeginner')); $ wp_admin_bar-> add_node ($ args); // Agrega el primer enlace secundario $ args = array ('id' => 'wpbeginner-guides', 'title' => 'WPBeginner Guides', 'href' => 'https://www.wpbeginner.com/category / beginners-guide / ',' parent '=>' wpbeginner ',' meta '=> array (' class '=>' wpbeginner-guides ',' title '=>' Visit WordPress Beginner Guides ')); $ wp_admin_bar-> add_node ($ args); // Agregar otro enlace secundario $ args = array ('id' => 'wpbeginner-tutorials', 'title' => 'WPBeginner Tutorials', 'href' => 'https://www.wpbeginner.com/category/ wp-tutorials / ',' parent '=>' wpbeginner ',' meta '=> array (' class '=>' wpbeginner-tutorials ',' title '=>' Visit WPBeginner Tutorials ')); $ wp_admin_bar-> add_node ($ args); // Agregar un enlace secundario al enlace secundario $ args = array ('id' => 'wpbeginner-themes', 'title' => 'WPBeginner Themes', 'href' => 'https: //www.wpbeginner. com / category / wp-themes / ',' parent '=>' wpbeginner-tutorials ',' meta '=> array (' class '=>' wpbeginner-themes ',' title '=>' Visita los Temas de WordPress Themes en WPBeginner ')); $ wp_admin_bar-> add_node ($ args); add_action ('admin_bar_menu', 'custom_toolbar_link', 999); 

How to add custom shortcut links to the WordPress toolbar

In this sample code, we first add a custom shortcut link. Next, we add another custom link and make it a child of the first link. We add the main link id by adding the argument 'parent' => 'wpbeginner' . We then repeat this to add another link under the same parent link. We've also used a secondary link as a primary link to show you how to add subitems to a subitem in the custom links menu.

We hope this article helped you add custom shortcuts to the WordPress toolbar on your website. For questions and comments please leave a comment. Comment.

What would you add as a custom shortcut link in your WordPress toolbar?