AI Verified

Name

Show Page Title in WordPress Menu

About

Adding HTML directly into a WordPress menu to dynamically fetch and display the page title is not supported through the WordPress menu editor interface out of the box. However, you can achieve dynamic content insertion in menus by using a custom theme or plugin that allows for shortcodes or PHP code execution within menus. Here's a way to do it through a custom shortcode.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

After adding the Snippet. Use the Shortcode in Your Menu 1. Go to Appearance > Menus in your WordPress dashboard. 2. Add a Custom Link to your menu. 3. In the URL field, put the URL of the page or a # if you want it to be non-clickable. 4. In the Link Text field, enter the shortcode: [current_page_title]. 5. Save the menu.

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

09/04/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Show Page Title in WordPress Menu

 
                    
1function custom_page_title_shortcode() {
2 return get_the_title();
3}
4add_shortcode('current_page_title', 'custom_page_title_shortcode');
5 
6function execute_shortcodes_in_menus($menu_item) {
7 if (strpos($menu_item->title, '[') !== false && strpos($menu_item->title, ']') !== false) {
8 $menu_item->title = do_shortcode($menu_item->title);
9 }
10 return $menu_item;
11}
12add_filter('wp_nav_menu_objects', 'execute_shortcodes_in_menus');

0

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

CLOUD Meister: Cleanup UI

Added: 1 year ago

Last Updated: 1 year ago

WordPress Admin

AI Verified

1

See who is Admin

Added: 1 year ago

Last Updated: 1 year ago

Been hacked and want to know who is Admin on your site and when got access?

WordPress Admin

AI Verified

0

enable autoupdater on specific time

Added: 1 year ago

Last Updated: 1 year ago

This enables the Autoupdater only between a specific time range.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.