Giter Site home page Giter Site logo

wp-menu-item-custom-fields's Introduction

WP Menu Item Custom Fields

Useful to easily append custom fields to WordPress menu items.

Usage

To get it going you need to include Menu.php into your theme or plugin.

require_once dirname( __FILE__ ) . '/Menu.php';

Then set up the list of custom fields into an array and pass it over as the argument when declaring a new Menu. Currently supports adding text fields and select dropdows.

An example:

add_action( 'init', 'setup_menu_custom_fields' );
function setup_menu_custom_fields() {

	$fields = array(
		'_mycustom_field_1' => array(
			'label' => __( 'Custom field 1', 'domain' ),
			'element' => 'input',
			'sanitize_callback' => 'sanitize_text_field',
			'attrs' => array(
				'type' => 'text',
				),
			),
		'_mycustom_field_2' => array(
			'label' => __( 'Custom field 2', 'domain' ),
			'element' => 'select',
			'sanitize_callback' => 'sanitize_text_field',
			'options' => array(
				'option-1' => __( 'Option 1', 'domain' ),
				'option-2' => __( 'Option 2', 'domain' ),
				),
			),
		);

		// Menu Management custom fields.
		new \Lucymtc\Menu( $fields );
}

wp-menu-item-custom-fields's People

Contributors

lucymtc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wp-menu-item-custom-fields's Issues

Ajax Not working

hai, thanks for u script, can i ask, why ajax not working on plugins?

Thanks! How do I use the field?

This is great. Thank you! How do I use the custom filed in a theme, template file or on the front end? Maybe you could add this to "Usage" in the Readme?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.