1

Is there a way I can allow the user to attach images as attachments to a post without allowing him to insert them within the text itself? Ideally the Upload Media button remains the same but the image is not inserted within the text.

The reason is I don't want users to start creating their own layouts and I want the template to always be consistent.

(I know there is a quick hack to just strip out tags in the content pages from the theme itself but that will just confuse my users, so I need a way to just attach images).

2
  • You could hook in on pre_save_post and strip those tags, but I think you're better off simply disabling all unwanted TinyMCE buttons.
    – kaiser
    Commented Oct 10, 2012 at 21:57
  • Stripping tags won't do because it will confuse users. They will start putting the images in and complaining that they're not appearing where they put them. I can disable TinyMCE buttons but the Upload/Insert dialog still has the button 'Insert into Post', so its not quite a solution either.
    – jbx
    Commented Oct 10, 2012 at 23:44

2 Answers 2

1

One way to do this would be to simply hide the upload/insert media button: and, then add featured image support for your themes posts, so a user can still attach images to the post.

Hide upload/insert media button for your theme in: functions.php:

function hideUploadInsert($hook)
{
    if($hook != 'post.php' AND $hook != 'post-new.php')
        return; // if not in the edit or new admin pages, for Posts or Pages, then do nothing.
    echo '<style type="text/css" media="screen">
        #wp-content-media-buttons {
            display: none;
        }
</style>';
}
add_action('admin_enqueue_scripts', 'hideUploadInsert');

Add featured image support to your themes posts in: functions.php

add_theme_support('post-thumbnails', array( 'post' ));


EDIT:

I didn't realize you were referring to attaching multiple images to a post. You could just use the css I gave above to hide the button for inserting images into a post: and, then use one of the plugins that come up in a google search for attaching multiple featured images to a post: https://www.google.ca/search?q=wordpress+multiple+featured+images

7
  • Thanks for your answer. Can you explain a bit more the featured image part? By default on my installation posts can already have a featured image. It is used for the thumbnails on the index page. However I need multiple image attachments to the post not one.
    – jbx
    Commented Oct 10, 2012 at 23:41
  • Ahhh. Please see my updated answer. Commented Oct 10, 2012 at 23:51
  • Thanks. Actually I was thinking of combining your answer together with this plugin wordpress.org/extend/plugins/attachments so that I keep the featured image (which seems to be intended more for the thumbnail in the index page) separate.
    – jbx
    Commented Oct 10, 2012 at 23:56
  • Are you sure the file to edit is style.css in my theme? It doesn't seem to work that way and when I inspect the page it doesn't seem that it is loading style.css from my theme in the admin pages.
    – jbx
    Commented Oct 11, 2012 at 0:02
  • LOL sorry, that was a total "Doh!" moment for me. You cannot style the admin area from your themes style.css file. Please see the top code area of my further updated answer for how to do this. Commented Oct 11, 2012 at 0:30
0

Maybe the following works:

add_filter( 'type_url_form_media', '__return_null' );

Anyway: The function is already deprecated and the whole UI will likely be reworked with 3.5 or 3.6, so this solution might not work for too long.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.