Add a reassociation add-on option for WordPress media files

WordPress comment 1K Reading mode

 Add a reassociation add-on option for WordPress media files

WordPress allows you to attach a media file association to an article, but the association cannot be modified by default. This tutorial will add an option to modify the attachment of a media file association.

Add the following code to the functions.php file of the current theme:

  1. add_filter( "manage_upload_columns" , 'upload_columns');
  2. add_action( "manage_media_custom_column" , 'media_custom_columns', 0, 2);
  3.  
  4. function  upload_columns( $columns ) {
  5.     unset( $columns ['parent']);
  6.      $columns ['better_parent'] =  "Parent" ;
  7.      return   $columns ;
  8. }
  9. function  media_custom_columns( $column_name $id ) {
  10.      $post  = get_post( $id );
  11.      if ( $column_name  !=  'better_parent')
  12.          return ;
  13.          if  (  $post ->post_parent > 0 ) {
  14.              if  ( get_post( $post ->post_parent) ) {
  15.                  $title  =_draft_or_post_title( $post ->post_parent);
  16.             }
  17.             ?>
  18.             <strong><a href= "<?php echo get_edit_post_link( $post->post_parent );  ?> " ><? php  echo   $title  ?></ a></strong>,  <? php  echo  get_the_time(__('Y/m/d'));  ?>
  19.             <br />
  20.             <a  class = "hide-if-no-js"  onclick= "findPosts.open('media[]','<?php echo $post->ID ?>'); return false; "  href= "#the-list" ><? php _e('Re-Attach');  ?></ a>
  21.             <? php
  22.         }  else  {
  23.             ?>
  24.             <? php _e('(Unattached)');  ?>< br />
  25.             <a  class = "hide-if-no-js"  onclick= "findPosts.open('media[]','<?php echo $post->ID ?>'); return false; "  href= "#the-list" ><? php _e('Attach');  ?></ a>
  26.             <? php
  27.         }
  28. }

Original text: How To Re-Attach Media Files In WordPress

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 anonymous

Comment

Anonymous netizens
 :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

Drag the slider to complete validation