Wordpress: how to add gallery button to post editor
Easy but this took me 3 hrs to find and make work Just add the code below to your functions.php There are two terrible pieces of code:
- String.fromCharCode(34) that adds double-quote
- data:image/jpg;base64,... that inserts nice image and allows to avoid path magic
Thanks this post's author for the idea how to do it.
function wp_myplugin_media_button($context) {
$wp_myplugin_media_button = '
'.'%s';
return sprintf($context, $wp_myplugin_media_button);
}
add_filter('media_buttons_context', 'wp_myplugin_media_button');
UPD: wrote everything above and checked how it looks :) The code for new button provided below:
<a onclick="tinyMCE.execCommand('mceInsertRawHTML', false,
'[gallery link='+String.fromCharCode(34)+'file'+String.fromCharCode(34)+
' columns='+String.fromCharCode(34)+'5'+String.fromCharCode(34)+']');
return false;" title="Добавить галерею">
<img src="data:image/jpg;base64,
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFR
AWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5Ojf/2wBDAQoKCg0MDRoPDx
o3JR8lNzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzf/
wAARCAAMAA4DASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAABQQG/8QAJBAAAgIB
AwQCAwAAAAAAAAAAAQIDBBEABRITFCExI0EyQlH/xAAUAQEAAAAAAAAAAAAAAAAAAAAE/8
QAHREAAQQCAwAAAAAAAAAAAAAAAQACAxEhcRIxsf/aAAwDAQACEQMRAD8Adsb3XG+2N
um3bsnjSNgJIUKnkit+RGc+fvTcTKm39dL8VvMvHnEV8DHo8dZq/wBlJfaafa6ss/FFMrSTAs
FUKMgOB6A+tXVr3XqNVStFDGrq/wAbOTnBH7Mf7pLpWmPjWdD3tFEbg67xsr//2Q==
"></a>