2012-09-20 96 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"'; 
} 
?>