Going to guess you would need something similar to:
function remove_shortcode_from_index($content) {
if ( is_home() ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter('the_content', 'remove_shortcode_from_index');
This example is perfect! Thanks Michael! Is there a way to make it work for the_content tags that are in a certain DIV perhaps?
It’s that now that I have this working I released I have a part on my index.php page that shows a Video Highlight and that uses shortcodes to display a Viper Video. Here is the code I use to pull the latest post to show the video:
<?php $my_query = new WP_Query('cat=1532&showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<?php the_content(''); ?>
<?php endwhile; ?>
Thanks again! I’m going to add that code as an example on the Codex for strip_shortcodes.
Michael, looking through the codex page for conditional tags, it’s seems I need to combine the above with something using the is_category(‘Video Highlight’) tag, but I’m not sure what the correct PHP code should be (I suck at PHP).
Thanks again!
dbaker – okay I put that example in the Codex Function_Reference/strip_shortcodes#Examples. Thanks for the suggestion.
Also note you may want to keep an eye on this trac ticket if you have problems:
http://core.trac.wordpress.org/ticket/10082
Finally, see Conditional Tags related to your last comment.
Hey Micheal,
Thanks so much for your detailed response.
I think the below code is the correct code for going through my home.php file, and stripping all shortcodes except for the posts that are in cat=438 (my video highlight category). But it gives a syntax error saying the ‘else’ line is bad. Like I said, my PHP sucks so any suggestions are greatly appreciated.
function remove_shortcode_from_index($content) {
if ( in_category('438') ) {
$content = $content;
}
return $content;
}
else ( is_home() ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter('the_content', 'remove_shortcode_from_index');
Thanks!
If ‘home’ and not in category 438
function remove_shortcode_from_index($content) {
if ( is_home() && !in_category('438') ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter('the_content', 'remove_shortcode_from_index');
Michael,
That’s amazing. I really have to learn PHP, you can do so much with it!
Thanks a lot!
DB