Pindahkan kotak meta kutipan ke editor konten di atas


11

Saya menemukan pengait WordPress yang disebut " edit_form_after_title" untuk menambahkan kotak teks setelah judul.

Bagaimana saya bisa menggunakan kait ini untuk menampilkan kutipan setelah judul sambil membuat posting baru?

Jawaban:


7

Ini sederhana, cukup batalkan registrasi postexcerptterlebih dahulu kemudian tambahkan satu lagi di atas.

Ini kode saya

add_action(
  'admin_menu', function () {
    remove_meta_box('postexcerpt', 'post', 'normal');
  }, 999
);

add_action('edit_form_after_title', 'post_excerpt_meta_box');

1
Hai beri +1 pada itu, tetapi bagaimana Anda mengatasi gaya setelah penghapusan meta_box?
DᴀʀᴛʜVᴀᴅᴇʀ

6

Saya beradaptasi dari sini: /wordpress//a/158485/373

/* -----------------------------------------
 * Put excerpt meta-box before editor
 * ----------------------------------------- */
function my_add_excerpt_meta_box( $post_type ) {
    if ( in_array( $post_type, array( 'post', 'page' ) ) ) {
         add_meta_box(
            'postexcerpt', __( 'Excerpt' ), 'post_excerpt_meta_box', $post_type, 'test', // change to something other then normal, advanced or side
            'high'
        );
    }
}
add_action( 'add_meta_boxes', 'my_add_excerpt_meta_box' );

function my_run_excerpt_meta_box() {
    # Get the globals:
    global $post, $wp_meta_boxes;

    # Output the "advanced" meta boxes:
    do_meta_boxes( get_current_screen(), 'test', $post );

}

add_action( 'edit_form_after_title', 'my_run_excerpt_meta_box' );

function my_remove_normal_excerpt() { /*this added on my own*/
    remove_meta_box( 'postexcerpt' , 'post' , 'normal' ); 
}
add_action( 'admin_menu' , 'my_remove_normal_excerpt' );

2
function jb_post_excerpt_meta_box($post) {
    remove_meta_box( 'postexcerpt' , $post->post_type , 'normal' );  ?>
    <div class="postbox" style="margin-bottom: 0;">
        <h3 class="hndle"><span>Excerpt</span></h3>
        <div class="inside">
             <label class="screen-reader-text" for="excerpt"><?php _e('Excerpt') ?></label>
             <textarea rows="1" cols="40" name="excerpt" id="excerpt">
                  <?php echo $post->post_excerpt; ?>
             </textarea>
        </div>
    </div>
<?php }

add_action('edit_form_after_title', 'my_post_excerpt_meta_box');

Dengan cara ini, Anda dapat menambahkan kotak kutipan sesuka Anda. Tetapi penting untuk menghilangkan kotak asli. Jika tidak, Anda tidak akan dapat menyimpan kutipan di kotak baru.


1

Jawaban ini mirip dengan yang @OzzyCzech diposting, tetapi lebih universal dan menambahkan header ke kotak kutipan. Satu kelemahan dari metode ini adalah Anda tidak dapat menyembunyikan kotak kutipan melalui Opsi Layar ... dalam hal ini Anda harus menggunakan jawabannya oleh @ lea-cohen.

add_action( 'edit_form_after_title', 'move_excerpt_meta_box' );
function move_excerpt_meta_box( $post ) {
    if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
        remove_meta_box( 'postexcerpt', $post->post_type, 'normal' ); ?>
        <h2 style="padding: 20px 0 0;">Excerpt</h2>
        <?php post_excerpt_meta_box( $post );
    }
}
Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.