Customize the excerpt meta box (4 posts)

  1. PaBLoX
    Posted 5 years ago #


    I'm trying to achieve something that (I believe) should be simple: I want to give the authors of the theme I'm developing the chance to write the "lead" of the news in the excerpt meta box, but I need to change the title from "excerpt" to "lead" and change the text that explains what an excerpt is. I want -basically- to use the box for another purpose, but keep using the actual functions (the_excerpt()) to get the content.

    I know that I can create a new meta box to achieve this, delete the excerpt box and then access the content by the custom fields, but sounds it's a lot of work for something simple enough.

    Until now my only step has been to change the title from Excerpt to Lead through this in the functions.php:

    function lead_meta_box() {
        add_meta_box( 'postexcerpt', 'Lead', 'post_excerpt_meta_box', 'post', 'normal', 'core' );
    add_action( 'admin_menu', 'lead_meta_box' );

    After reading for a while I found that the best 'tool' to modify the core functions from wordpress is through the add_filter, so I searched where is the 'helping text' below the box. It happens to be in the wp-admin/includes/meta-boxes.php in the function:

    function post_excerpt_meta_box($post) {
    <label class="screen-reader-text" for="excerpt"><?php _e('Excerpt') ?></label><textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt ?></textarea>
    <p><?php _e('Excerpts are optional hand-crafted summaries of your content that can be used in your theme. <a href="http://codex.wordpress.org/Excerpt" target="_blank">Learn more about manual excerpts.</a>'); ?></p>

    After looking some add_filter examples on how to modify the bloginfo() core function, I tried -naively- to do the same with the already mentioned function:

    add_filter('post_excerpt_meta_box','my_excerpt_box', 1, 2);
    function my_excerpt_box($post) { ?>
    <label class="screen-reader-text" for="excerpt"><?php _e('Excerpt') ?></label><textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt ?></textarea>
    <p><?php _e('Blabla new text'); ?></p> <?php

    As you can imagine, nothing happened (not even an error), so I decided to post here my question to see if someone could help me or guide me through my objective (it'll help me to understand the add_filter stuff too :P)


  2. Reuben Gunday
    Posted 5 years ago #

    I don't think you can achieve it through filters/actions. Have you tried removing the excerpt box and adding your own?

    http://codex.wordpress.org/Function_Reference/remove_meta_box (look at 2nd example)

  3. PaBLoX
    Posted 5 years ago #

    I haven't yet, it looks like a lot of code for something simple that I'm trying to achieve. I'll give it a try though.

    Thanks for answering!

  4. akisok2
    Posted 4 years ago #

    The easiest solution I've discovered is to go to edit-form-advanced.php in the wp-admin folder and look for line 129:

    if ( post_type_supports($post_type, 'excerpt') )
    	add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');

    Modify the content inside the _('Excerpt') and you should be good to go.

Topic Closed

This topic has been closed to new replies.

About this Topic