• Resolved Trahald

    (@trahald)


    I’m trying to add filters on search results pages (where the URL is for instance ?s=test&x=31&y=17). For instance

    add_filter('the_content', 'content_filter');
    add_filter('wp_title', 'title_filter');
    add_filter('the_title', 'title_filter');

    On Page pages, these filters work fine. On search results pages, they don’t have any effect.

    I’m also adding actions, but those do not. Filters however do not. Why might filters be failing on search results pages, while actions still work?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Those filters are only going to work if your search results page calls them or calls a function that calls them. So I guess the question is what does your search results page look like?

    Thread Starter Trahald

    (@trahald)

    I don’t really understand what you mean. It’s just the standard search results. I just tried with the Default theme and it doesn’t work with that either.

    Ok. The concept of ‘standard search results’ is a little bit odd with WP because themes can easily override the default, and often do. But lets start with the simplest case. That would be the search results page that ships with the default theme. the_content() isn’t going to work with that results page because its never called, but both ‘the_title’ and ‘wp_title’ work for me, so what does your title_filter function look like?

    Thread Starter Trahald

    (@trahald)

    Looks like it’s as you say – the_title works with the default theme but the_content does not. Thanks.

    What template files do I edit to add these filters to the search results page? How do I add these filters?

    With the default theme the page you want is wp-content/themes/default/search.php. You’ll see a more or less normal loop except that the_content isn’t there. By the way, if you just delete or rename search.php, WP will use index.php for the search results at least with a default install.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Filters not working on search results pages (the_content etc.)’ is closed to new replies.