Remove filter for pages only

Asked

Viewed 51 times

2

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

The problem is that it is showing in the posts and also in the pages, I wanted to show only in the POSTS, I tried so 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 in the posts, but it is printing on the pages also (Buyer’s name: and Buyer’s email:). How to remove these page impressions?

2 answers

5


Try to add conditional tags inside 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;

}
  • Raphael, I’m trying: if(is_single() || !is_page_template('template_fullwidth.php', 'page.php')) and he doesn’t want to consider page.php, pq?

  • For page.php you can use is_page(), thus getting your parole tag: if(is_single() || !is_page_template('page.php') || !is_page()) or if(is_single() && !is_page_template('page.php') && !is_page()).

0

Here’s what I did, and it worked:

function my_content($content) {

if(is_single() || !is_page_template('template_fullwidth.php') $content .= "Buyer’s 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');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.