Custom Fields
Re-Envisioned
Support MB Settings Page Set meta tags by setting pages

  • Creator
    Topic
  • #24295
    Resolved Martin Rybos
    Participant

    Hi. How to get rwmb_meta on page ?

    I have an setting page.

    
    //mainsettingspage
    
    // Register a theme options page
    add_filter( 'mb_settings_pages', function ( $settings_pages ) {
        $settings_pages[] = array(
            'id'          => 'dimainsettings',
            'option_name' => 'DiSettings',
            'menu_title'  => 'DiSettings',  
            'icon_url'    => 'dashicons-edit',
            'style'       => 'no-boxes',
            'columns'     => 1,
            'tabs'        => array(
                'general' => 'General Settings',
                'faq'     => 'FAQ & Help',
            ),
        );
        return $settings_pages;
    });
    
    //mainsettingspage
    
    add_filter( 'rwmb_meta_boxes', 'meta_box_group_demo_register' );
    function meta_box_group_demo_register( $meta_boxes ) {
        
    //mainsettingspage
    
    $meta_boxes[] = array(
            'id'             => 'general',
            'title'          => 'General',
            'settings_pages' => 'dimainsettings',
            'tab'            => 'general',
            'fields' => array(
                array(
                    'name' => 'Logo',
                    'id'   => 'logo',
                    'type' => 'file_input',
                ),
                
                array(
                    'name'        => 'Meta Description',
                    'id'          => 'meta_description',
                   'type'        => 'textarea',
                    'placeholder' => 'Meta Description',
                    'rows'        => 4, 
                ),
                
                array(
                    'name'        => 'Meta Keywords',
                    'id'          => 'meta_keywords',
                   'type'        => 'textarea',
                    'placeholder' => 'Meta Description',
                    'rows'        => 4, 
                ),
                
                
            ),
        );
     );
    

    I put the rwmb code to page and need to get values.

    
    <?php 
        $metades = rwmb_meta( $meta_description, ['object_type' => 'setting'], $DiSettings );
        $metakey = rwmb_meta( $meta_keywords, ['object_type' => 'setting'], $DiSettings );   
        ?>
    
    <meta name="description" content="<?php echo $metades;?>">
     <meta name="keywords" content="<?php echo $metakey;?>">
    
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #24296
    Long Nguyen
    Moderator

    Hi,

    Follow this documentation to get the setting value https://docs.metabox.io/extensions/mb-settings-page/#getting-field-value, your code looks good to get meta description and meta keywords and show them. Did you see it works?

    #24297
    Martin Rybos
    Participant

    Hi.Thanks.I can’t get it to work. I have something wrong there. But i’m close

     
    
    $value = rwmb_meta( $field_id, ['object_type' => 'setting'], $option_name ); 
    echo $value;
    

    $field_id – is field ID of meta_description
    [‘object_type’ => ‘setting’] – remains unchanged or i need to rename setting ?

    $option_name – opton name of setting page – DiSettings in my case

    Do i need to add bellow hook to my php to get it work ?

    
    add_action( 'mb_settings_page_load', function ( $args ) {
        if ( $args['id'] === 'dimainsettings' ) {
            // Do something
        }
    }, 20 );
    
    
    #24298
    Martin Rybos
    Participant

    I probably don’t put the code in the right place.
    I’m mixing a meta box with settings
    whole code is: https://pastebin.com/PPRYQz6v

    #24305
    Long Nguyen
    Moderator

    Hi Martin,

    I’ve added your code to the file functions.php then show the page settings in the file header.php of the theme but not see any issue.

    <head>
        <meta charset="<?php bloginfo( 'charset' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10.0, user-scalable=yes">
        <link rel="profile" href="http://gmpg.org/xfn/11">
        <?php wp_head(); ?>
        <?php 
        $metades = rwmb_meta( 'meta_description', ['object_type' => 'setting'], 'DiSettings' );
        $metakey = rwmb_meta( 'meta_keywords', ['object_type' => 'setting'], 'DiSettings' );   
        ?>
    
        <meta name="description" content="<?php echo $metades;?>">
        <meta name="keywords" content="<?php echo $metakey;?>">
    </head>

    Can you please check your variable $meta_description, $DiSettings if it is assigned to the field ID?

    $metades = rwmb_meta( $meta_description, ['object_type' => 'setting'], $DiSettings );

    #24309
    Martin Rybos
    Participant

    I think it is.

    
    add_filter( 'mb_settings_pages', function ( $settings_pages ) {
        $settings_pages[] = array(
            'id'          => 'dimainsettings', //settings field ID
            'option_name' => 'DiSettings',    // $option_name 
            'menu_title'  => 'DiSettings',  
            'icon_url'    => 'dashicons-edit',
            'style'       => 'no-boxes',
            'columns'     => 1,
            'tabs'        => array(
                'general' => 'General Settings',
                'faq'     => 'FAQ & Help',
            ),
        );
        return $settings_pages;
    });
    
    add_filter( 'rwmb_meta_boxes', 'meta_box_group_demo_register' );
    function meta_box_group_demo_register( $meta_boxes ) {
        
    //mainsettingspage
    
    $meta_boxes[] = array(
            'id'             => 'general',
            'title'          => 'General',
            'settings_pages' => 'dimainsettings', 
            'tab'            => 'general',
            'fields' => array(
                array(
                    'name' => 'Logo',
                    'id'   => 'logo',
                    'type' => 'file_input',
                ),
                
                array(
               'name'        => 'Meta Description',
            'id'          => 'meta_description', //    field ID
                   'type'        => 'textarea',
                    'placeholder' => 'Meta Description',
                    'rows'        => 4, 
                ),
                
                array(
                    'name'        => 'Meta Keywords',
                    'id'          => 'meta_keywords',
                   'type'        => 'textarea',
                    'placeholder' => 'Meta Description',
                    'rows'        => 4, 
                ),
                
                
            ),
        );
       
        $meta_boxes[] = array(
            'id'             => 'info',
            'title'          => 'Theme Info',
            'settings_pages' => 'dimainsettings',
            'tab'            => 'faq',
            'fields'         => array(
                array(
                    'type' => 'custom_html',
                    'std'  => 'Having questions? Check out our documentation',
                ),
            ),
        );
    
    //mainsettingspage  
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.