Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPressプラグイン内でメディアアップローダーを使用してファイル名を選択しテキストフィールドに挿入する
<h3>My Picture (1)</h3>
<input type="text" id="my_media_1" name="my_media_1" value="" />
<a class="media-upload" href="JavaScript:void(0);" rel="my_media_1">Select File</a>
<h3>My Picture (2)</h3>
<input type="text" id="my_media_2" name="my_media_2" value="" />
<a class="media-upload" href="JavaScript:void(0);" rel="my_media_2">Select File</a>
jQuery('document').ready(function(){
jQuery('.media-upload').each(function(){
var rel = jQuery(this).attr("rel");
jQuery(this).click(function(){
window.send_to_editor = function(html) {
imgurl = jQuery('img', html).attr('src');
jQuery('#'+rel).val(imgurl);
tb_remove();
}
formfield = jQuery('#'+rel).attr('name');
tb_show(null, 'media-upload.php?post_id=0&type=image&TB_iframe=true');
return false;
});
});
});
<?php
add_action('admin_print_scripts-'.$hook_suffix, 'my_admin_scripts');
add_action('admin_print_styles-'.$hook_suffix, 'my_admin_styles');
function my_admin_styles() {
wp_enqueue_style('thickbox');
}
function my_admin_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_script('jquery');
}
?>
@miya0001

This comment has been minimized.

Copy link
Owner Author

commented May 15, 2011

詳細は以下のページで。
http://firegoby.theta.ne.jp/archives/2261

@cloudsben

This comment has been minimized.

Copy link

commented May 7, 2013

cool, I like it.

@finzaiko

This comment has been minimized.

Copy link

commented Nov 10, 2015

Thanks for plugin that help to control all code just from gist, sometime I want full write my sentence blog in my markdown file, it is possible add more feature can be embed auto split main front blog

@frndlyy

This comment has been minimized.

Copy link

commented Sep 4, 2016

Love the plugin Oembedgist. I was struggling for over a week trying to figure out how to do this natively with WordPress and some other plugins but this one did the job. WordPress won't let me post reviews as I am a new member so here is a tip for anyone who installs the plugin but unable to post a single gist file using the example provided by the author.

The URL for a single gist has to be in the format https://gist.github.com/frndlyy/e7e51d3acddee51c4e42d0ee9bbe0dc0#file-aduser_create_bulk_users.ps1

and not https://gist.github.com/frndlyy/e7e51d3acddee51c4e42d0ee9bbe0dc0#file-aduser_create_bulk_users-ps1

Notice the difference. You have to copy the actual file name (.ps1 file extension) and not the URL when you click on the gist file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.