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…
Apparently you are simply not translating your logic into code: