• Resolved jhmilcom

    (@jhmilcom)


    I’ve done fairly simple conditional tags before, but I’m having troubles figuring out how to do this using code on our blog that was created by someone else.

    The following code is set up to display an ad after the 3rd paragraph across our entire blog. However, I would like to modify this to set a condition to display the ad everywhere (all Pages, Posts, etc.) EXCEPT for a certain Page (ID=5481).

    I’m too much of a novice to know exactly what I need to do in order to correctly set up the “! is_page(5481)” (is not Page 5481) conditional tag to not display the ad if it’s Page 5481 but everywhere else otherwise.

    Any guidance from someone more experienced in conditional tags would be greatly appreciated.

    // Content after paragraph 3rd
    function p3_content($content){
    	//return $content."test";
    	$con = split("</p>", $content);
    	if($con[count($con)] == "") array_pop($con);
    	$ret = "";
    	ob_start();
    	for($i=0; $i<count($con); $i++){
    		echo $con[$i]."</p>";
    		if($i == 2){
    			echo "<div id='content-middle'>";
    			dynamic_sidebar('content-middle');
    			echo "</div>";
    		}
    	}
    	$postOutput = ob_get_contents();
    	ob_end_clean();
    	return $postOutput;
    }
    add_filter('the_content', 'p3_content');
Viewing 2 replies - 1 through 2 (of 2 total)
  • Something like:

    // Content after paragraph 3rd
    function p3_content($content){
    	if( is_page('5481)') ) return $content;
    [ ... ]
    }
    add_filter('the_content', 'p3_content');

    should work.

    Thread Starter jhmilcom

    (@jhmilcom)

    Thank you so much. That’s exactly what I needed to make it happen.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional tags – How to display content on all except one particular Page’ is closed to new replies.