WORDPRESS apply_filters only home page

I have a simple function (in functions.php in my theme) which adds class to the navigation links

   add_filter('next_posts_link_attributes', 'posts_link_attributes');
   add_filter('previous_posts_link_attributes', 'posts_link_attributes');

  function posts_link_attributes() {
     if (is_home() || is_front_page()) {
        if (current_filter() == 'previous_posts_link_attributes') {
            return 'class="prevlink ajax"';
        }
        elseif (current_filter() == 'next_posts_link_attributes') {
            return 'class="nextlink ajax"';
        }
     }
  }

I need this to only work on my homepage but it does not work.
Anyone can help me?

Related posts

1 comment

  1. I solved the problem adds filters to index.php

    add_filter('next_posts_link_attributes', 'posts_link_attributes');
    add_filter('previous_posts_link_attributes', 'posts_link_attributes');
    

    I do not know if this is correct but it works properly. Will it be caused any problems?

Comments are closed.