php function 不执行,functions.php内部的jQuery脚本不起作用

我无法在自定义主题的function.php wordpress文件中使用此Jquery脚本。有人能帮我吗。问题是, 当我单击浏览按钮以插入不允许我进入的图像而只是不执行任何操作时, 当我进入wordpress管理员中的自定义帖子类型时。

这是代码(是的, 没有显示一个开放的php标签。)

function show_your_images_meta_box() {

global $post;

$meta = get_post_meta( $post->ID, 'your_images', true ); ?>

Upload Poster Image

<?php%20echo%20%24meta%5B'image'%5D;%20?>

// Instantiates the variable that holds the media library frame.

var meta_image_frame;

// Runs when the image button is clicked.

$('.image-upload').click(function(e) {

// Prevents the default action from occuring.

e.preventDefault();

var meta_image = $(this).parent().children('.meta-image');

// If the frame already exists, re-open it.

if (meta_image_frame) {

meta_image_frame.open();

return;

}

// Sets up the media library frame

meta_image_frame = wp.media.frames.meta_image_frame = wp.media({

title: meta_image.title, button: {

text: meta_image.button

}

});

// Runs when an image is selected.

meta_image_frame.on('select', function() {

// Grabs the attachment selection and creates a JSON representation of the model.

var media_attachment = meta_image_frame.state().get('selection').first().toJSON();

// Sends the attachment URL to our custom image input field.

meta_image.val(media_attachment.url);

//var image_url = meta_image.val();

//$(selected).closest('div').find('.image-preview').children('img').attr('src', image_url);

});

// Opens the media library frame.

meta_image_frame.open();

});

});

#1

可能是Wordpress附带的jQuery默认设置为兼容模式, 这意味着$快捷方式不起作用。请参阅此处:在WordPress中使用” $”代替” jQuery”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值