2

I am using the simple add_filter function to output the content.

add_filter('the_content', 'my_name');

function my_name( $content ){
  // code
  return $content;
}

When I activate the plug-in output of the function my_name is shown in all pages. How can I restrict the output to only one page?

2

Add this code and replace yourpagename with the your page slug on which u want this filter to execute

function my_name( $content ) {
    global $post;
    if ( $post->post_name == 'yourpagename' ) {          
        return $content;
    } 
}
add_filter( 'the_content', 'my_name' );
  • I tried with 'about' for 'yourpagename', does not print any thing, how to enter this value? – Naveen May 7 '13 at 12:33
  • if ( $post->post_name == 'about' ) about should be slug of the page. – dipali May 7 '13 at 12:48
  • @naveenkumar Welcome – dipali May 7 '13 at 13:25
  • @naveenkumar If the answer works for you, please mark it as Accepted. (Just click the little checkmark on the left.) – Pat J May 7 '13 at 14:39
  • @PatJ, use this reference: How does accepting an answer work ;) – brasofilo May 7 '13 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.