WordPress.org

Ready to get started?Download WordPress

Forums

Trouble with add_filter (5 posts)

  1. masterix
    Member
    Posted 6 years ago #

    Hi everyone!

    I'm writing my first plugin and I have to face with probably small problem. I have such a code:
    add_filter( 'the_content', 'my_func' );
    And it works, but when I put something like this:

    if( is_page() )
    {
      add_filter( 'the_content', 'my_func' );
    }

    It doesn't work. The question is of course "why?".

    And BTW: I check if is it a static page or post by checking post_type in DB. Is there any better solution?

    Thanks in advance for any help!

  2. whooami
    Member
    Posted 6 years ago #

    Is there any better solution?

    I dont know about better, but there is another way -- dont put page checking in your plugin. Write the plugin, then call the plugin based on is_page.

  3. masterix
    Member
    Posted 6 years ago #

    It's good idea too. But what about the first question? Why doesn't it work?

  4. masterix
    Member
    Posted 6 years ago #

    I made my own is_page() function but didn't overload the built-in one, it is why it didn't work ;)

  5. getincss
    Member
    Posted 5 years ago #

    Hi, masterix! Did you find a way for you problem? I get this one and can't find solution on forum :(

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags