0

I am declaring this filter in my function.php file:

<?php add_filter('next_posts_link_attributes', 'posts_link_attributes'); function posts_link_attributes() { return 'class="styled-button"'; } ?> 

but get this back:

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

Because I use next_post_link() in index.php

Is there a solution for this? a reason this doesn't work?

Thanks for your help guys!

2 Answers 2

1

Make the callback more specific.

<?php add_filter('next_posts_link_attributes', 'posts_link_attributes_style_button'); function posts_link_attributes_style_button() { return 'class="styled-button"'; } ?> 

To test if a function exists:

if(function_exists('posts_link_attributes')){ } 
Sign up to request clarification or add additional context in comments.

3 Comments

awesome thanks that works! I didn't know it was already "used" :).
@SnippetSpace No prob. Just added how to check if a function exists.
just did! had to wait for the time limit
0

Change your function name to something else:

<?php add_filter('next_posts_link_attributes', 'my_posts_link_attributes'); function my_posts_link_attributes() { return 'class="styled-button"'; } ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.