Custom Fields
Re-Envisioned
Support General Need help to display single_image field on the frontend with shortcode

  • Creator
    Topic
  • #29226

    Hi there,

    I have created a settings page with one custom field (single_image). I would like to display the image in the header of my website next to my logo.

    I tried to use this shortcode but the image is not showing up: [rwmb_meta id="single_image_qn3i1fz9we"]

    Alternatively I tried to add the code to This is the theme file:

    <?php
    /**
     * Template part for displaying the header branding/logo
     *
     * @package kadence
     */
    
    namespace Kadence;
    rwmb_the_value( $single_image_qn3i1fz9we, array( 'size' => 'thumbnail' ) );
    
    ?>
    <div class="site-header-item site-header-focus-item" data-section="title_tagline">
        <?php
        /**
         * Kadence Site Branding
         *
         * Hooked Kadence\site_branding
         */
        do_action( 'kadence_site_branding' );
        ?>
    </div><!-- data-section="title_tagline" -->

    But I don see the image show up next to the logo either. Could you please show me how I should add the image to the above template?

    This is how I have set up the settings page and single_image field:

    //JP Metabox.io create settings page
    add_filter( 'mb_settings_pages', 'location_specific_settings' );
    
    function location_specific_settings( $settings_pages ) {
        $settings_pages[] = [
            'menu_title'  => __( 'Location Specific Settings', 'location-specific-settings' ),
            'option_name' => 'Location Specific Settings',
            'position'    => 25,
            'parent'      => 'index.php',
            'style'       => 'no-boxes',
            'columns'     => 1,
            'icon_url'    => 'dashicons-admin-generic',
        ];
    return $settings_pages;
    }
    // JP add logo custom field to settings page
    add_filter( 'rwmb_meta_boxes', 'custom_logo' );
    
    function custom_logo( $meta_boxes ) {
        $prefix = '';
    
    $meta_boxes[] = [
        'title'          => __( 'Logo', 'logo' ),
        'id'             => 'logo',
        'settings_pages' => ['location-specific-settings'],
        'fields'         => [
            [
                'name'       => __( 'Single Image', 'logo' ),
                'id'         => $prefix . 'single_image_qn3i1fz9we',
                'type'       => 'single_image',
                'image_size' => 'medium',
            ],
        ],
    ];
    
    return $meta_boxes;
    }
Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #29232
    Long Nguyen
    Moderator

    Hi Jan,

    The option name should be in lower case and separate by underscore _ or hyphen -. For example

    $settings_pages[] = [
            'menu_title'  => __( 'Location Specific Settings', 'location-specific-settings' ),
            'option_name' => 'location_specific_settings',
            'position'    => 25,
            'parent'      => 'index.php',
            'style'       => 'no-boxes',
            'columns'     => 1,
            'icon_url'    => 'dashicons-admin-generic',
        ];
    

    then you can use the shortcode to show the single image

    [rwmb_meta id="single_image_qn3i1fz9we" object_id="location_specific_settings" object_type="setting"]

    or PHP code

    $image = rwmb_meta( 'single_image_qn3i1fz9we', ['object_type' => 'setting'], 'location_specific_settings' );
    echo '<img src="' . $image['full_url'] . '">';

    Get more details on the documentation
    https://docs.metabox.io/shortcode/#examples
    https://docs.metabox.io/extensions/mb-settings-page/#getting-field-value

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.