2012-09-20 69 views
0

我声明我function.php文件这个过滤器:添加WordPress的过滤器错误

<?php 
add_filter('next_posts_link_attributes', 'posts_link_attributes'); 

function posts_link_attributes() { 
    return 'class="styled-button"'; 
} 
?> 

,但把它恢复:因为我的index.php

使用next_post_link()

Fatal error: Cannot redeclare posts_link_attributes() (previously declared in functions.php in index.php)

有没有解决方案?这不起作用的原因?

感谢您的帮助!

回答

1

使回调更具体。

<?php 
add_filter('next_posts_link_attributes', 'posts_link_attributes_style_button'); 

function posts_link_attributes_style_button() { 
    return 'class="styled-button"'; 
} 
?> 

为了测试一个函数存在:

if(function_exists('posts_link_attributes')){ 

} 
+0

真棒感谢的作品!我不知道它已经被“使用”了:)。 – cmplieger

+0

@SnippetSpace没有问题。刚刚添加了如何检查函数是否存在。 – iambriansreed

+0

感谢您的信息,非常有帮助:) – cmplieger

0

更改您的函数名称到别的东西:

<?php 
add_filter('next_posts_link_attributes', 'my_posts_link_attributes'); 

function my_posts_link_attributes() { 
    return 'class="styled-button"'; 
} 
?>