How to create custom fields on my child theme?

Asked on September 4, 2015 in Development.

Hello guys.

I want to create custom meta fields page options on my child theme pages. I’m not good wordpress developer and i want to add custom fields. Please help me and teach me.

Thanks

olziinaa Layers User

(see answer below)

on September 5, 2015.

Hello. I want to add Custom Meta on my page options with video url.

 add_filter(' layers_custom_meta ',' look_add_custom_meta ');
 if( !function_exists( 'look_add_custom_meta' ) ) {
    function look_add_custom_meta($custom_meta) {
        $custom_meta['post'] = array (
            'title' => LAYERS_THEME_TITLE . __( ': Options' , 'layerswp' ),
             'description' => __( 'Meta Description' , 'layerswp' ), // @TODO
             'position' => 'normal',
             'custom-meta' => array(
                 'media' => array(
                    'title' => __( 'Meta Title' , 'layerswp' ),
                     'elements' => array(
                         'video-url' => array(
                             'label' => __( 'Video URL' , 'layerswp' ),
                             'description' => __( 'For use with <a href="' . esc_url( 'http://codex.wordpress.org/' ) . 'Embeds" target="_blank">oEmbed</a> supported media' , 'layerswp' ),
                             'type' => 'text',
                        )
                     )
                 )
             )
        );
    }
 }

it not works. how can i do this?

on September 6, 2015.

add_filter( 'layers_custom_meta', 'look_add_custom_meta' );

if( !function_exists( 'look_add_custom_meta' ) ) {

function look_add_custom_meta( $custom_meta ){

$custom_meta['post'] = array(

'title' => LAYERS_THEME_TITLE . __( ': Options' , 'layerswp' ),

'description' => __( '' , 'layerswp' ), // @TODO

'position' => 'normal',

'custom-meta' => array(

'media' => array(

'title' => __( 'Rich Media' , 'layerswp' ),

'elements' => array(

'video-url' => array(

'label' => __( 'Video URL' , 'layerswp' ),

'description' => __( 'For use with <a href="' . esc_url( 'http://codex.wordpress.org/' ) . 'Embeds" target="_blank">oEmbed</a> supported media' , 'layerswp' ),

'type' => 'text',

)

)

),

'title' => array(

'title' => __( 'Title Options' , 'layerswp' ),

'elements' => array(

'pd-top' => array(

'label' => __( 'Padding Top' , 'layerswp' ),

'description' => __( 'Padding Top Size' , 'layerswp' ),

'type' => 'text',

),

'pd-bottom' => array(

'label' => __( 'Padding Bottom' , 'layerswp' ),

'description' => __( 'Padding Top Size' , 'layerswp' ),

'type' => 'text',

)

)

)

)

);

// Page Meta we just emulate the post meta

$custom_meta['page'] = $custom_meta['post'];

return $custom_meta;

}

}

added this code on my child theme functions.php it works but second tab (Title Options) now showing. How can i show it.
Thanks for the help me.

on September 7, 2015.
Reply
  • Possible Answers to Your Question:

  • 2 Answer(s)
    Answered on September 8, 2015. Best answer

    Hi there,

    Filtering layers_custom_meta is currently not a good way to add your own meta fields.  You must use the conventional route via add_meta_box to begin building your own panel. You can use the layers framework form() and input() types to take advantage of the pre-existing styling if you prefer, otherwise the core field types can be used and your own panel styling applied.

     

    Here is our guide on using Layers_Form_Elements to build custom fields:
    https://docs.layerswp.com/how-to-add-custom-fields-to-posts-and-pages/

    Vail Joy Layers Team
    Reply
    Answered on September 5, 2015.

    The documentation on this is pretty thorough, check out this page – i’m going to be working through this myself next week so I can let you know how I get on.

    https://docs.layerswp.com/create-an-extension-adding-customizer-controls/

    Essentially you want to add the code to your child themes functions.php file. I did a quick test now and this broke my theme, so it will require some thinking – it’s straight out of the documentation though so perhaps the theme author can shed some light on why it doesn’t work??

    // ADD A NEW PANEL
    add_filter('layers_customizer_panels','layers_child_customizer_panels', 40);
    
    if( !function_exists( 'child_customizer_panels' ) ) {
    function child_customizer_panels( $panels ){
    $panels['theme-options'] = array(
    'title' => __( 'Theme Options' , 'child' ),
    'description'=> __( 'Your custom description.' , 'child' ),
    'priority' => 130
    );
    return $panels;
    }
    
    // ADD A SECTINO TO YOUR NEW PANEL
    add_filter('layers_customizer_sections','layers_child_customizer_sections', 100);
    
    if( !function_exists( 'child_customizer_sections' ) ) {
    function child_customizer_sections( $sections ){
    $sections[ 'header-social-media' ] = array(
    'title' => __( 'Social Media Profiles' , 'child' ),
    'panel' => 'theme-options',
    );
    return $sections;
    }
    }
    // ADD CONTROLS TO YOUR NEW SECTION
    add_filter('layers_customizer_controls','layers_child_customizer_controls', 100);
    
    function yourtheme_customizer_controls( $controls ){
    $controls[ 'section-name' ] = array(
    'option-one' => array(
    'type' => 'layers-text',
    'label' => __( 'Option One' , 'mytheme_textdomain' )
    ),
    'option-two' => array(
    'type' => 'layers-text',
    'label' => __( 'Option Two' , 'mytheme_textdomain' )
    )
    );
    return $controls;
    }
    Reply