• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom Field in post editor

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom Field in post editor

This topic is: resolved

Tagged: advanced custom field, funtion.php, genesis, Wordpress

  • This topic has 2 replies, 2 voices, and was last updated 11 years, 11 months ago by viorelepuran.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • April 16, 2014 at 11:56 pm #100904
    viorelepuran
    Member

    Hello!
    I want to add a custom field , that will be visible in post editor, just below the field for post`s title.
    I know about the Advanced Custom Filed plugin, i have used that with success, but now i want to get that same functionality without using a plugin, i need to do this throw theme`s funtion.php.

    So basicly, i need a text box below the box for the post title, and i need to know what will the meta key be named, so i can pull it in side posts.

    Thank you for reading and trying to help me!

    April 17, 2014 at 2:54 am #100916
    Brad Dalton
    Participant

    You can hand code this and hook it in the exact position you want.


    Tutorials for StudioPress Themes.

    April 17, 2014 at 3:02 am #100918
    viorelepuran
    Member

    Thank you Brad, i googled it, and i added a custom meta box, with a text field. now i can pull the value of that field, and i did it all in my function.php.
    This is the code i used:

    / Little function to return a custom field value
    function wpshed_get_custom_field( $value ) {
    global $post;

    $custom_field = get_post_meta( $post->ID, $value, true );
    if ( !empty( $custom_field ) )
    return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) );

    return false;
    }

    // Register the Metabox
    function wpshed_add_custom_meta_box() {
    add_meta_box( 'wpshed-meta-box', __( 'Ebay listing', 'textdomain' ), 'wpshed_meta_box_output', 'post', 'side', 'high' );
    }
    add_action( 'add_meta_boxes', 'wpshed_add_custom_meta_box' );

    // Output the Metabox
    function wpshed_meta_box_output( $post ) {
    // create a nonce field
    wp_nonce_field( 'my_wpshed_meta_box_nonce', 'wpshed_meta_box_nonce' ); ?>

    <p>
    <label for="wpshed_textfield"><?php _e( 'Keyword', 'textdomain' ); ?>:</label>
    <input type="text" name="wpshed_textfield" id="wpshed_textfield" value="<?php echo wpshed_get_custom_field( 'wpshed_textfield' ); ?>"/>
    </p>

    <?php
    }

    // Save the Metabox values
    function wpshed_meta_box_save( $post_id ) {
    // Stop the script when doing autosave
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    // Verify the nonce. If insn't there, stop the script
    if( !isset( $_POST['wpshed_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['wpshed_meta_box_nonce'], 'my_wpshed_meta_box_nonce' ) ) return;

    // Stop the script if the user does not have edit permissions
    if( !current_user_can( 'edit_post' ) ) return;

    // Save the textfield
    if( isset( $_POST['wpshed_textfield'] ) )
    update_post_meta( $post_id, 'wpshed_textfield', esc_attr( $_POST['wpshed_textfield'] ) );

    }
    add_action( 'save_post', 'wpshed_meta_box_save' );

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Custom Field in post editor’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble