0

by default I use the author.php template and it's working fine but I need to make a parent page for author.php like facebook and other social sites.

I want to do something like this:

site.com/author/trello/settings

site.com/author/trello/personalinformation
0

You can add this pages with new rewrite rules like that :

add_action("init", function () {

    add_rewrite_tag("%specialAuthor%", "([^&]+)");

    foreach (["personalinformation", "settings"] as $specialAuthor) {

        add_rewrite_rule(
              "author/([^/]+)/($specialAuthor)/?$"
            , "index.php?author_name=\$matches[1]&specialAuthor=\$matches[2]"
            , "top"
        );

    }

});


add_filter("author_template_hierarchy", function ($templates) {

    $specialAuthor = get_query_var("specialAuthor", NULL);

    if (isset($specialAuthor)) {

        $author = get_queried_object();

        $templates = [
            "$specialAuthor-{$author->user_nicename}.php",
            "$specialAuthor-{$author->ID}.php",
            "$specialAuthor.php",
        ];

    }

    return $templates;

});

the first time, flush the rewrite rules : https://codex.wordpress.org/Function_Reference/flush_rewrite_rules

and after that, copy author.php to personalinformation.php in the theme for the URL site.com/author/.../personalinformation

  • Thank you for your time and answer, I copy author.php to personalinformation.php and try to go to localhost/author/name/settings but it's got 404 error. – Trello Oct 8 '17 at 11:59
  • have you flushed the rewrite rules ? you can do that in the administration, "Settings" -> "Permalinks" and just click Save Changes without any changes. – mmm Oct 8 '17 at 12:05
  • Sorry, I forget this, I make this now and it's working yes but it's not getting the personalinformation.php content it's got an archive page for a custom post type, I hope you understand me. – Trello Oct 8 '17 at 12:09
  • Please be known that when i copy author.php to the custom post type archive file it's working without any problem and get the users the problem only that it's not getting the file that you choose (personalinformation.php). – Trello Oct 8 '17 at 12:18
  • my code add 2 endpoints. the endpoint /settings use settings.php and the the endpoint /personalinformation use personalinformation.php – mmm Oct 8 '17 at 14:52
0

WordPress can't do that on its own. Author pages are only archives for users with published posts. What you need is more of a social network use for WordPress, and you should try BuddyPress plugin: BuddyPress. It will create member pages for all users, and it will have different pages for each user: profile edit, profile view, settings... It might be more then you need, but that is closest to having profiles active.

There are other plugins for membership based website where you can have extensive profiles for users, you can find them on WordPress repository: Members plugins on WP.org.

  • I don't need to use any another membership plugin or BuddyPress my site is already a social network theme, so there's any another solution to make it work? This question really is very important for all. – Trello Oct 8 '17 at 11:05
  • If your theme is social network theme, it should already have membership area implemented, or it depends on some plugin to do so. You can either use an existing plugin or create a plugin that will do what you need. It can't be done with WordPress as it is, it requires a complex setup with the handling of custom pages you want each user to have, rewrite rules to expand urls... – Milan Petrovic Oct 8 '17 at 11:07

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.