Set meta tags by setting pages
Support › MB Settings Page › Set meta tags by setting pagesResolved
- This topic has 5 replies, 2 voices, and was last updated 4 years, 2 months ago by
Martin Rybos.
-
AuthorPosts
-
February 2, 2021 at 6:59 PM #24295
Martin Rybos
ParticipantHi. 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;?>">
February 2, 2021 at 9:49 PM #24296Long Nguyen
ModeratorHi,
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?
February 2, 2021 at 10:31 PM #24297Martin Rybos
ParticipantHi.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 );
February 2, 2021 at 10:50 PM #24298Martin Rybos
ParticipantI probably don't put the code in the right place.
I'm mixing a meta box with settings
whole code is: https://pastebin.com/PPRYQz6vFebruary 3, 2021 at 10:29 AM #24305Long Nguyen
ModeratorHi 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 );
February 3, 2021 at 4:26 PM #24309Martin Rybos
ParticipantI 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
-
AuthorPosts
- You must be logged in to reply to this topic.