Remove filter only for pages

2

I needed to create a filter to print the name and email of users within the posts ( the_content ) they created.

The problem is that it is showing in the posts and also in the pages, I wanted to show only in POSTS, I tried it and it did not work:

function my_content($content) {
    $content .= "<b>Nome do comprador:</b> " . usp_get_meta(false, 'usp-author') . "<br />";
    $content .=  "<b>Email do comprador:</b> " . usp_get_meta(false, 'usp-email');
    return $content;
}

if (!is_page_template('page.php')) 
remove_filter('the_content','my_content');

else
add_filter('the_content','my_content');

It shows right on the posts, but it's printing on the pages too (Buyer Name: and Buyer Email :). How do I remove these impressions from the pages?

    
asked by anonymous 18.10.2014 / 17:56

2 answers

5

Try adding conditional tags within your filter,

function my_content($content) {

   if(is_single() || !is_page_template('page.php') || !is_page())
       $content .= "<b>Nome do comprador:</b> " . usp_get_meta(false, 'usp-author') . "<br />";
       $content .=  "<b>Email do comprador:</b> " . usp_get_meta(false, 'usp-email');

   return $content;

}
    
18.10.2014 / 18:02
0

I did the following, and it worked:

function my_content($content) {

if (is_single () ||! is_page_template ('template_fullwidth.php'))        $ content.=" Buyer name: ". usp_get_meta (false, 'usp-author'). "
";

return $ content; }       add_filter ('the_content', 'my_content');

  function my_content2($content) {

if (is_single () ||! is_page_template ('template_fullwidth.php'))

   $content .=  "<b>Email do comprador:</b> " . usp_get_meta(false, 'usp-email') . "<br />";

return $ content; }       add_filter ('the_content', 'my_content2');

    
18.10.2014 / 19:00