Walker News

How To Insert Multiple Images In WordPress 2.6 Without Using Shortcode?

Starting from WordPress 2.5, uploading multiple images or files is as easier as those who are using New Blogger platform provided by Google Inc. Question: Other than using shortcode, is there other ways to do so?

Intro: WordPress 2.5+ could upload multiple files in one go

Unlike New Blogger image uploader, the WordPress 2.5+ “select files to upload” dialog box works exactly a standard Windows file selection dialog box – press CTRL+A to select all images files; CTRL+Mouse-click to select multiple files; highlight first picture file and press SHIFT key while selecting the last picture file to select all files in between, inclusively.

The WordPress 2.5+ image file uploader allow any number of images per upload in one go. I.e. you’re not limited to a maximum 5 images per single upload, as in New Blogger.

It’s cool, isn’t it? Not only that. With WordPress 2.5+, you could also use “WordPress Gallery Shortcode” to insert multiple images to the post editor!

As the name suggest, the WordPress Gallery Shortcode is like Linux alias command but it’s pre-defined in WordPress core files (i.e. general user couldn’t redefine the shortcode in the plain/default WordPress admin pages).

However, some WordPress fans is not really keen on the image shortcode for some reasons, e.g. it can’t define which image of the gallery to display or not to display, the sequence of displaying each image in the gallery, etc.

How to insert multiple images in WordPress 2.6.1?

I am using WordPress version 2.6.1 for this topic, but the original trick I’m referring to was suggested by beardedknight in WordPress forum for WordPress 2.5 (so, it supports to work fine for version 2.5+).
  1. Edit the wp-admin/includes/media.php file (read carefully the path specified here, it’s not wp-includes/media.php or elsewhere – there are at least 3 media.php files in WordPress 2.6.1. installation directory):
    function media_send_to_editor($html) {
            ?>
    <script type="text/javascript">
    /* <![CDATA[ */
    var win = window.dialogArguments || opener || parent || top;
    win.send_to_editor('<?php echo addslashes($html); ?>');
    /* ]]> */
    </script>
            <?php
            //exit;
            return;
    }

    As shown here, look for the media_send_to_editor($html) function and make little changes, as those highlighted in “blue colour” PHP code:
    • remark the original exit; line
    • add one single PHP code return;
       
  2. Edit wp-admin/js/media-upload.js:
    function send_to_editor(h) {
            if ( typeof tinyMCE != 'undefined' && ( ed = tinyMCE.activeEditor ) && !ed.isHidden() ) {
                    ed.focus();
                    if (tinymce.isIE)
                          ed.selection.moveToBookmark(tinymce.EditorManager.activeEditor.windowManager.bookmark);
    
                    if ( h.indexOf('[caption') != -1 )
                            h = ed.plugins.wpeditimage._do_shcode(h);
    
                    ed.execCommand('mceInsertContent', false, h);
            } else
                    edInsertContent(edCanvas, h);
    
            //tb_remove();
    }

    As shown here, look for the send_to_editor(h) function and remark the original tb_remove(); function call (the “blue colour” JavaScript code).

If you’re not comfortable with this simple PHP code modification (PHP mod), then just stick to the default behaviour or look for some good WordPress gallery plugin. Good luck.

Custom Search

  1. How To Change WordPress Image Caption Text Style To Superscripts? – Walker News 09-09-08@00:36

    […] 2.5+ rewrite the image/file uploader interface to include some most wanted features, e.g. multiple images per single upload, WordPress Gallery Shortcode, image caption text, image size and alignment, etc. Question: How […]

  2. gus 19-11-08@06:10

    Okay, this looks promising, but I don’t get what the result of the code change will be.

  3. amit das 02-06-10@22:40

    i used the above code mods for wp 2.9.2 but is not working… i uploaded multiple images and after saving all changes..when i am using insert into post..the dialog disappears like it was before.

  4. Marko 26-09-10@05:35

    Works great! It will save the time to reopen the stupid ajax box.
    I really don’t understand why WordPress does not add an “insert all images” button. They want to force people to use the gallery (which uses hardcoded (!) style definitions in the media.php file)!
    It just shows that WordPress is run by idiots for idiots.

    The mod would be even better if it stayed on the same page and just added a “done inserting” message to the page with ajax… should not be too difficult to do. :-)

2017  •  Privacy Policy