0

I wanna have

  • example.com/post-name -> uses template1.php

  • example.com/post-name/details -> uses template2.php

I found this discussion, so I implemented the codes in my theme’s functions.php. I also made the changes from the older replies but I get this error

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'detail_rewrite_rules' not found or invalid function name in /public_html/wp-includes/plugin.php on line 173

I didn’t edit plugin.php and on line 173 is:

$value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));

I hope someone can help me, it seems a fairly easy job but I might be wrong.

1 Answer 1

1

If you look at the function you'll see there's an error :

function detail_rewrite_rule( $rules ) {
  $newrules = array();
  $newrules['(.+?)/([^/]+)(/[0-9]+)?/detail/?$'] = 'index.php?category_name=$matches[1]&name=$matches[2]&page=$matches[3]&detail=1'; 

  return $newrules + $rules;
}
add_filter( 'rewrite_rules_array','detail_rewrite_rules' );

The callback is not the same : detail_rewrite_rule, detail_rewrite_rules.

In the add_filter you have to provide the same name for function. Otherwise this won't be hooked in WordPress. So you can fix it with :

add_filter( 'rewrite_rules_array','detail_rewrite_rule' );//without the s
2
  • Thank you for your answer @jMau , yes that was the problem, but now i get this error >Fatal error: Can't use function return value in write context in /home/keezme/public_html/wp-content/themes/vid/functions.php on line 1596` , on line 1596 i have ` return (!empty(locate_template($templates))) ? locate_template($templates) : $template;` if i remove the line, the error disapear but the code is not working , if i go to example.com/mypost/detail/ i get a 404 error Aug 22, 2013 at 11:26
  • I did not check the function. But with a quick look I can see this is not great quality. You'd better ask a detailed question here.
    – JMau
    Aug 22, 2013 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.