WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditional tags - How to display content on all except one particular Page (3 posts)

  1. jhmilcom
    Member
    Posted 1 year ago #

    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');
  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Something like:

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

    should work.

  3. jhmilcom
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic