0

I have a client that wants two pages for each author profile:

First Page - has user info, bunch of social media links, etc. Using author.php for this.
Second Page - list of author posts

I've built everything, and here's my question:

Is there a way to have get_author_posts_url() use a template other than author.php?

  • Not an answer but a suggestion: I think is easier to handle author profiles (pages with just author info, no posts) with some plugin for "user profiles", there are a lot, and keep using author.php for what it is intended. – cybmeta Sep 4 '13 at 14:28
2

There is a filter called author_link. You can use that change the URL to whatever you want.

add_filter(
  'author_link', 
  function ($link, $author_id, $author_nicename) {
    var_dump($link, $author_id, $author_nicename); // debug
    return $link; // return your modified URL
  },
  1,3
);

The question does not have enough detail to allow for more specific code.

You can use the template_include hook to alter the template that loads in much the same way as the above code alters URL.

function author_archive_wpse_112852($template) {
  if (/* not sure what your conditions are */) {
    $template = get_stylesheet_directory().'/diff-author-template.php';
  }
  return $template;
}
add_filter('template_include','author_archive_wpse_112852');
  • Thanks for your response. This is exactly what I want to do. But how can I use template_include only when using the get_author_posts_url() function? That's the only condition. – chowwy Sep 4 '13 at 14:17
  • Your condition doesn't make a lot of sense to me. get_author_posts_url() just creates an URL. When you click that URL you have a new request-- that function isn't involved. I suppose you could tack on a GET string-- ?my_special_author=true. I am starting to think that you have an XY problem though. – s_ha_dum Sep 4 '13 at 14:31
  • Could be :( What I'm trying to say is that when clicking on the link created by get_author_posts_url(), WP automatically uses the author.php template to display the results. I want to use a different template when that link is clicked on. – chowwy Sep 4 '13 at 14:35
  • Anyway, I've accepted and upvoted your answer, since it was very helpful. At least we've moved the ball forward. – chowwy Sep 4 '13 at 14:41
  • The code above should let you 1) alter the URL created by get_author_posts_url and 2) change the template that loads. I don't understand why you want to do that or what your precise conditions are. If I did understand those issues I suspect there is another solution but until there is a better explanation.... – s_ha_dum Sep 4 '13 at 14:45
0

In case anyone needs to solve this kind of issue, I found another question on here that contains all of the necessary steps, including those found in the accepted answer on this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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