Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to hide/remove Caption in Insert Media (WP)

Options
  • 30-11-2014 7:48pm
    #1
    Registered Users Posts: 2,343 ✭✭✭


    Hi all,

    I want to hide the 'Caption' label and field that is below the 'ATTACHMENT DETAILS' and on the edit details (see screenshots).

    I've hidden it on the wp-admin/includes/media.php file:
    <div class="wp_attachment_details edit-form-section">
    		<p>
    			<label class="hidden" for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
    			<textarea class="widefat hidden" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
    		</p><!--Added hidden to label and textarea- 30/11/2014- Craig B-->
    

    Probably not ideal but if there is anything else I can do from my functions.php instead, please let me know.

    -C


Comments

  • Registered Users Posts: 6,177 ✭✭✭Talisman


    You don't want to be hacking WordPress core files. If you don't want your client to see the fields then use CSS to hide them.


  • Registered Users Posts: 2,343 ✭✭✭red_bairn


    Talisman wrote: »
    You don't want to be hacking WordPress core files. If you don't want your client to see the fields then use CSS to hide them.

    I managed to come across this bit in the codex about loading a set of CSS and/or Javascript documents to all admin pages and this guys post.


  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    You should be using the attachment_fields_to_edit.

    Probably something like this (untested)
    [PHP]<?php
    function dc_remove_caption_field( $form_fields, $post ) {
    unset($form_fields);

    return $form_fields;
    }
    add_filter( 'attachment_fields_to_edit', 'dc_remove_caption_field', 10, 2 );
    ?>[/PHP]

    You might have to use other filters too for when you are adding


  • Registered Users Posts: 2,343 ✭✭✭red_bairn


    daymobrew wrote:
    Probably something like this (untested)


    I think that only happens on the Edit Page. I tried that before. I'm currently in transit so can't test of at the moment.


  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    I have not had any luck with my earlier code but this code removed the 'Caption' box when I edit an image in a page/post.
    [php]function dc_disable_captions() {
    return true;
    }
    add_filter('disable_captions', 'dc_disable_captions');
    [/php]
    Then I did a quick search for 'wordpress remove field from media upload' and found a gem on the always excellent StackExchange. As the solution is delicate (if WordPress changes the template then the modified template would need to be updated), the suggestion to use CSS to hide the relevant items is probably the safest - use the admin_enqueue_scripts action.


  • Advertisement
  • Registered Users Posts: 2,343 ✭✭✭red_bairn


    daymobrew wrote:
    . As the solution is delicate (if WordPress changes the template then the modified template would need to be updated), the suggestion to use CSS to hide the relevant items is probably the safest - use the


    You clearly didn't bother reading my second post.


  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    red_bairn wrote: »
    You clearly didn't bother reading my second post.
    Ouch.


Advertisement