Skip to main content
added 814 characters in body
Source Link

I'm trying to create a function to display either a theme option or custom images based on user input.

So basically, it's a custom meta box. The user selects either a display header image OR they can upload one they want to use.

I've created a custom function to call later on the single page template. This is what I have so far.

//El display image
function el_display(){
    global $post;
    $eldisplay = get_post_meta($post->ID, '_cmb_el_theme', true);
    $elcustomdisplay = get_post_meta($post->ID, '_cmb_custom_image', true);
        
        if(isset($eldisplay)){
            echo '<img src="' . $eldisplay . '" />';
                }elseif(isset($elcustomdisplay)){
                echo '<img src="' . $elcustomdisplay . '" />';
            }else{
                echo '<img src="' . EL_IMG . 'mobile-development.jpg' . '" />';
            }
}

When I call the function later (using el_display(); ), there is no display image showing. I'm a little stuck and have been trying to fix this for hours.

Any help would be much appreciated, thanks!


UPDATE Ok, thanks to all for helping me out and pointing me in the right direction. I do have some code clean up to do and a possible all out change in code but I'll use this for now.

I got it to work with the following code.

//El display image
function el_display(){
    global $post;
    $eldisplay = get_post_meta($post->ID, '_cmb_el_theme', true);
    $elcustomdisplay = get_post_meta($post->ID, '_cmb_custom_image', true);
        
        if(!empty($eldisplay)){
            echo '<img src="' . $eldisplay . '" />';
                }elseif(!empty($elcustomdisplay) && isset($elcustomdisplay)){
                echo '<img src="' . $elcustomdisplay . '" />';
            }else{
                echo '<img src="' . EL_IMG . 'mobile-development.jpg' . '" />';
            }
}

Thanks again!

I'm trying to create a function to display either a theme option or custom images based on user input.

So basically, it's a custom meta box. The user selects either a display header image OR they can upload one they want to use.

I've created a custom function to call later on the single page template. This is what I have so far.

//El display image
function el_display(){
    global $post;
    $eldisplay = get_post_meta($post->ID, '_cmb_el_theme', true);
    $elcustomdisplay = get_post_meta($post->ID, '_cmb_custom_image', true);
        
        if(isset($eldisplay)){
            echo '<img src="' . $eldisplay . '" />';
                }elseif(isset($elcustomdisplay)){
                echo '<img src="' . $elcustomdisplay . '" />';
            }else{
                echo '<img src="' . EL_IMG . 'mobile-development.jpg' . '" />';
            }
}

When I call the function later (using el_display(); ), there is no display image showing. I'm a little stuck and have been trying to fix this for hours.

Any help would be much appreciated, thanks!

I'm trying to create a function to display either a theme option or custom images based on user input.

So basically, it's a custom meta box. The user selects either a display header image OR they can upload one they want to use.

I've created a custom function to call later on the single page template. This is what I have so far.

//El display image
function el_display(){
    global $post;
    $eldisplay = get_post_meta($post->ID, '_cmb_el_theme', true);
    $elcustomdisplay = get_post_meta($post->ID, '_cmb_custom_image', true);
        
        if(isset($eldisplay)){
            echo '<img src="' . $eldisplay . '" />';
                }elseif(isset($elcustomdisplay)){
                echo '<img src="' . $elcustomdisplay . '" />';
            }else{
                echo '<img src="' . EL_IMG . 'mobile-development.jpg' . '" />';
            }
}

When I call the function later (using el_display(); ), there is no display image showing. I'm a little stuck and have been trying to fix this for hours.

Any help would be much appreciated, thanks!


UPDATE Ok, thanks to all for helping me out and pointing me in the right direction. I do have some code clean up to do and a possible all out change in code but I'll use this for now.

I got it to work with the following code.

//El display image
function el_display(){
    global $post;
    $eldisplay = get_post_meta($post->ID, '_cmb_el_theme', true);
    $elcustomdisplay = get_post_meta($post->ID, '_cmb_custom_image', true);
        
        if(!empty($eldisplay)){
            echo '<img src="' . $eldisplay . '" />';
                }elseif(!empty($elcustomdisplay) && isset($elcustomdisplay)){
                echo '<img src="' . $elcustomdisplay . '" />';
            }else{
                echo '<img src="' . EL_IMG . 'mobile-development.jpg' . '" />';
            }
}

Thanks again!

Source Link

Image not showing using a custom function and get_post_meta

I'm trying to create a function to display either a theme option or custom images based on user input.

So basically, it's a custom meta box. The user selects either a display header image OR they can upload one they want to use.

I've created a custom function to call later on the single page template. This is what I have so far.

//El display image
function el_display(){
    global $post;
    $eldisplay = get_post_meta($post->ID, '_cmb_el_theme', true);
    $elcustomdisplay = get_post_meta($post->ID, '_cmb_custom_image', true);
        
        if(isset($eldisplay)){
            echo '<img src="' . $eldisplay . '" />';
                }elseif(isset($elcustomdisplay)){
                echo '<img src="' . $elcustomdisplay . '" />';
            }else{
                echo '<img src="' . EL_IMG . 'mobile-development.jpg' . '" />';
            }
}

When I call the function later (using el_display(); ), there is no display image showing. I'm a little stuck and have been trying to fix this for hours.

Any help would be much appreciated, thanks!