I want to hide a certain paragraph from the SINGLE POST in WordPress via PHP content filter.
I developed this filtering script, which works like a sunshine:
function hideDaStuff( $content ) {
$paragraphs = explode( '</p>', $content );
foreach ($paragraphs as $index => $paragraph) {
if(6 == $index){
$paragraphs[$index] = '<p>Hidden for you ma friend.</p>';
}else{
$paragraphs[$index] .= '</p>';
}
}
return implode( '', $paragraphs );
}
add_filter( 'the_content', 'hideDaStuffForDaStranger' );
function hideDaStuffForDaStranger( $content ) {
if ( is_single() && ! is_user_logged_in() ) {
$content = hideDaStuff( $content );
}
return $content;
}
The problem is that WP cache caches the page whatever happens. So if a logged in user visits the page, then the content will show for everybody, and viceversa.
How can I make this specific part cache-independent, while keeping an efficient cache?
Using latest WP version and WP cache.
Thank you.
2
Answers
Actually no need of these filters. Use this format
Put only single condition