WordPress.org

Forums

[resolved] Else if and Shortcodes (8 posts)

  1. cmdshiftdesign
    Member
    Posted 3 years ago #

    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 ) ?>
  2. tresinvolved
    Member
    Posted 3 years ago #

    <?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; ?>
  3. cmdshiftdesign
    Member
    Posted 3 years ago #

    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)

  4. tresinvolved
    Member
    Posted 3 years ago #

    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?

  5. Digital Raindrops
    Member
    Posted 3 years ago #

    Do you need to supply the shortcode function name!

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

    HTH

    David

  6. cmdshiftdesign
    Member
    Posted 3 years ago #

    whoa whoa whoa... OK.. no.. it DID work! THANK YOU!
    :)

  7. Digital Raindrops
    Member
    Posted 3 years ago #

    ?? what worked share for others please ??

    Mark this as resolved please.

    David

  8. cmdshiftdesign
    Member
    Posted 3 years ago #

    see the code above by tresinvolved for resolution.

Topic Closed

This topic has been closed to new replies.

About this Topic