WORDPRESS apply_filters唯一的主页


WORDPRESS apply_filters only home page

我有一个简单的函数(在我的主题中.php函数中),它将类添加到导航链接中

   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"';
        }
     }
  }

我需要它只在我的主页上工作,但它不起作用。有人可以帮助我吗?

我解决了将过滤器添加到索引的问题.php

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

我不知道这是否正确,但它工作正常。会引起任何问题吗?