我创建了一个自定义元素,例如'自定义链接'来自functions.php中的WordPress,用户可以在其中添加名称,网址和图片。它还有一个CSS的自定义类。
但是点击“添加到菜单”按钮'没有任何反应,任何想法为什么?
这是我的functions.php的副本:
class logo_custom_element {
public function add_nav_menu_meta_boxes() {
/**
* Adds the meta box container
*/
add_meta_box(
'add-custom-logo',
__( 'Logo' ),
array( $this, 'render_meta_box_content'),
'nav-menus',
'side',
'low'
);
}
/**
* Render Meta Box content
*/
public function render_meta_box_content() {
global $_nav_menu_placeholder, $nav_menu_selected_id;
?>
<div class="customlinkdiv" id="customlogodiv">
<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
<input type="hidden" class="menu-item-classes" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-classes]" value="nav-product-image">
<p id="menu-item-url-wrap" class="wp-clearfix">
<label class="howto" for="menu-item-url"><?php _e( 'URL' ); ?></label>
<input id="menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
</p>
<p id="menu-item-name-wrap" class="wp-clearfix">
<label class="howto" for="menu-item-name"><?php _e( 'Link Text' ); ?></label>
<input id="menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox" />
</p>
<p id="menu-item-img-wrap" class="wp-clearfix">
<label class="howto" for="menu-item[<?php echo $_nav_menu_placeholder; ?>][image]"><?php _e( 'Logo URL' ); ?></label>
<input type="button" class="button right image-upload" value="Zoeken in media..."><br>
<input type="text" class="regular-text menu-item-textbox meta-image" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][image]" id="menu-item[<?php echo $_nav_menu_placeholder; ?>][image]" value="<?php echo $meta['image']; ?>">
<div class="image-preview" style="background-color: #f1f1f1;">
<img src="<?php echo $meta['image']; ?>" style="max-width: 100%;">
</div>
</p>
<script>
jQuery(document).ready(function ($) {
var meta_image_frame;
$('.image-upload').click(function (e) {
var meta_image_preview = $(this).parent().parent().children('.image-preview');
e.preventDefault();
var meta_image = $(this).parent().children('.meta-image');
if (meta_image_frame) {
meta_image_frame.open();
return;
}
meta_image_frame = wp.media.frames.meta_image_frame = wp.media({
title: meta_image.title,
button: {
text: meta_image.button
}
});
meta_image_frame.on('select', function () {
var media_attachment = meta_image_frame.state().get('selection').first().toJSON();
meta_image.val(media_attachment.url);
meta_image_preview.children('img').attr('src', media_attachment.url);
});
meta_image_frame.open();
});
});
</script>
<p class="button-controls wp-clearfix">
<span class="add-to-menu">
<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button submit-add-to-menu right" value="<?php esc_attr_e('Toevoegen'); ?>" name="add-custom-menu-item" id="customlogodiv" />
<span class="spinner"></span>
</span>
</p>
</div>
<?php }
}
$custom_nav = new logo_custom_element;
add_action( 'admin_init', array( $custom_nav, 'add_nav_menu_meta_boxes' ));
保存的值我想用自定义助行器加载,谢谢!