Retrieving Single Image URL in Oxygen Builder

Support MB Builder Retrieving Single Image URL in Oxygen BuilderResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23976
    Bret CarmichaelBret Carmichael
    Participant

    Hi there,

    I am using Oxygen and am trying to display a single_image that uploaded to a post.

    I created a function with the hope that it would output the image's URL, but it doesn't return anything.

    function mb_cp_logo_shortcode() {
    $image = rwmb_meta( 'info', array( 'size' => 'full' ) );
    echo '<a href="', $image['full_url'], '"><img src="', $image['url'], '"></a>';
    }
    add_shortcode( 'mb-cp-logo', 'mb_cp_logo_shortcode' );
    

    I based the function off of this page, https://docs.metabox.io/fields/single-image/, but I clearly didn't implement it correctly.

    I did a search before posting. I found the below topic, but it didn't get me where I needed.

    https://support.metabox.io/topic/retrieving-image-in-post-from-new-field/

    Thanks!

    #23979
    Long NguyenLong Nguyen
    Moderator

    Hi Bret,

    There are two points you need to notice:

    function mb_cp_logo_shortcode() {
        $image = rwmb_meta( 'info', array( 'size' => 'full' ) );
        return '<a href="'. $image['full_url']. '"><img src="'. $image['url']. '"></a>';
    }
    add_shortcode( 'mb-cp-logo', 'mb_cp_logo_shortcode' );
    • If you add the shortcode when editing the post with the Oxygen Builder, you don't need to pass the third-argument $post_id to the shortcode. But if you add the shortcode to the Grid Builder of Oxygen and insert the Grid when editing the post, you have to pass the post ID to the shortcode.
    function mb_cp_logo_shortcode() {
        $image = rwmb_meta( 'info', array( 'size' => 'full' ), 123 );
        return '<a href="'. $image['full_url']. '"><img src="'. $image['url']. '"></a>';
    }
    add_shortcode( 'mb-cp-logo', 'mb_cp_logo_shortcode' );

    See more in the documentation https://docs.metabox.io/rwmb-meta/#arguments.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.