How to Add a Post Introduction Form to WordPress

Asked 2 years ago, Updated 2 years ago, 89 views

How can I add an introduction posting form to WordPress, such as the image below?

Enter a description of the image here

wordpress

2022-09-29 22:22

1 Answers

Adding custom fields is easy using the plug-in without editing functions.php.
There are many plug-ins, so please search for 'Add custom fields to plug-ins' and select the plug-in that suits your needs.

However, I will write below how to not use the plug-in.
You can add custom fields in textarea by adding the following code to the functions.php of the theme:
Before you edit functions.php, back up functions.php and do it carefully.

 function_add_field()
{
    add_meta_box(
        'field-name', // input id
        'Introduction', // Display Title
        '_addmetabox', // Callback function name
        'post' // screen
    );
}
add_action('add_meta_boxes', '_add_field');

function_addmetabox($post)
{
    $value = get_post_meta($post->ID, 'introduction_sentence', true);
    echo'<textarea name="introduction_sentence" style="width:100%;height:200px">'.$value.'</textarea>';;
//    wp_editor($value, 'introduction_sentence');
    wp_nonce_field('nonce_key', 'namenonce');
}

function_save_field($post_id)
{
    if(!isset($_POST['namenonce'])
    || !check_admin_refer('nonce_key', 'namenonce')
    {return$post_id;}

    update_post_meta(
            $post_id,
            'introduction_sentence',
            $_POST ['introduction_sentence']
    );
    return$post_id;
}
add_action('save_post','_save_field');


2022-09-29 22:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.