• Resolved cmdshiftdesign

    (@cmdshiftdesign)


    I currently have a theme set to display a Featured Image (if set)
    But if no Featured Image is set, then any active widgets display instead…

    I want to change this to display a Featured Image if set, and if none is set to run a short code…

    This is the PHP currently

    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    
    <img src="<?php echo $image[0]; ?>">
    
     <?php /* Widgetized sidebar, if you have the plugin installed. */
        else:if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    <?php endif; ?> 
    
    <?php endif; ?>

    and this is the php to call on a shortcode…

    <?php echo do_shortcode( $content ) ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • <?php
    if (has_post_thumbnail( $post->ID ) ): 
    
    	$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    	<img src="<?php echo $image[0]; ?>">
    
    <?php else:
    
    	$content = 'Maybe some text, [someshortcode] maybe more text';
    	echo do_shortcode( $content );		
    
    endif; ?>
    Thread Starter cmdshiftdesign

    (@cmdshiftdesign)

    this has got to be close, cause it’s returning the “Maybe some text, maybe more text” but not recognizing/translating the shortcode (and I am sure the shortcode is correct)

    So the shortcode works elsewhere in your theme? And you’re returning it, not echoing the results in the shortcode function?

    Is that code above going in a template?

    Do you need to supply the shortcode function name!

    echo do_shortcode( '[my-shortcode]' );

    HTH

    David

    Thread Starter cmdshiftdesign

    (@cmdshiftdesign)

    whoa whoa whoa… OK.. no.. it DID work! THANK YOU!
    🙂

    ?? what worked share for others please ??

    Mark this as resolved please.

    David

    Thread Starter cmdshiftdesign

    (@cmdshiftdesign)

    see the code above by tresinvolved for resolution.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Else if and Shortcodes’ is closed to new replies.