Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When there is a specific shortcode in a post (example [sc]anything[/sc]), I want to hide the featured and take it's place. How can I do that?

I add this on my theme function

// TopWide Shortcode
function wpsite_topwide( $atts, $content = null ){
    return '<div class="topwide">' . do_shortcode($content) . '</div>';
}
add_shortcode( 'topwide', 'wpsite_topwide' );

/** 
 * Find if content has topwide shortcode in it. 
 */ 
function wpsite_has_topwide_shortcode() { 
    global $post; 

    if ( ! is_single() ) 
        return; 

    if ( false === strpos( $post->post_content, '[topwide' ) ) 
        return false; 

    return true; 
}

and this on single post

<?php
if (wpsite_has_topwide_shortcode() && has_post_thumbnail() ) { 
    echo '<div class="topwide">' . get_the_post_thumbnail( $post->ID, 'full' ) . '</div>'; 
} 
?>

But doesn't takes the place of the featured image in the post...

share|improve this question
    
I think the shortcode detection part has a solution here, try to dig in the archives –  brasofilo Mar 15 '13 at 18:26
    
@brasofilo I tried, but I think something I have done wrong, check plz if you can help me –  Alex Mar 15 '13 at 20:45

1 Answer 1

Apparently you are simply not translating your logic into code:

  • if it has shortcode, do this,
  • if not has shortcode but has thumbnail, do that,
  • otherwise, do something else.
if ( wpsite_has_topwide_shortcode() ) { 
    echo 'shortcode';
} elseif( has_post_thumbnail() ) {
    echo get_the_post_thumbnail( $post->ID, 'full' );
} else {
    echo 'Hello World';
}
share|improve this answer
    
this: <?php if ( wpsite_has_topwide_shortcode() ) { get_shortcode(); } elseif( has_post_thumbnail() ) { get_the_post_thumbnail( $post->ID, 'full' ) } ?> ? –  Alex Mar 15 '13 at 21:39
    
Did you try it? :) - But, yes, this is it. –  brasofilo Mar 15 '13 at 21:45
    
yes, i get this: Parse error: syntax error, unexpected '}' in /home/xx/public_html/wp-content/themes/xxxx/content-single.php on line 71 –  Alex Mar 15 '13 at 21:46
    
You have a missing semi-colon ; in get_the_post_thumb. A good IDE would have shown that, eg, NetBeans. –  brasofilo Mar 15 '13 at 21:55
    
now i get unexpected ';' :/ –  Alex Mar 15 '13 at 22:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.