Contents
How to add a data attribute to a WordPress website?
Rather than attempting to target the menu item with id == ?? which could change at some point (the menu item, not the id), use the WP Admin area to add a custom class to the menu item you want to target. Then use that class in your Javascript to trigger the information you need:
Adding Custom Attributes To WordPress Menus Step 1: The Plugin Creation Step 2: Adding Custom Fields Filter Step 3: Saving Custom Fields Step 4: The Form Step 5: Custom Field Output Step 6: Call The Walker! Sweet Custom Menu Plugin
How to save custom menu field value in WordPress?
Even if the custom “sub-title” field doesn”t really exist we must create a function that will save its value on menu edition. Menu elements are in two wards custom post types, so we can use the custom post type APIs and post_meta method. So, to save custom menu field value, add this function under rc_scm_add_custom_nav_fields ():
If you want to add some more fields to the menu, simply duplicate these lines and copy & paste them. Once this step is done, the menu should be working in the administration. You should now be able to see the new “sub-title” field when adding a new element to a menu. If it’s not the case, make you followed the tutorial step by step.
How to get custom field value in WordPress?
Here we use “ROOM TYPES” and click “Add Field” to create new fields. After you add “New Field”, fill in the field (see below). Field label and field name type the similar one, the first one is for display and the second one is used in attribute coding.
What are the two main fields in WordPress?
By default, when you write a new post, page, or any content type, WordPress saves it into two different areas. The first part is the body of your content that you add using the post editor. The second part is the information about that particular content. For example, title, author, date, time, and more.
What happens when you write a new WordPress post?
By default, when you write a new post, page, or any content type, WordPress saves it into two different areas. The first part is the body of your content that you add using the post editor.
In most part of the time, walkers are used to modify the HTML output of a menu. Here, we are working on the admin menu output form. Simply add this function to your main class: and then this to the constructor: What this does is replacing the default admin edit menu form by a custom one.