Kyle Tripp
Kyle Tripp

Reputation: 79

Wordpress Page Template 404

I have a file I created called profile.php in my themes folder and at the top of the file I declared Template name: Profile

I then went into wordpress admin and created a page called Profile using that template

On the website itself I want to be able to add some sort of custom text to the url so itll look like this: www.mysite.com/profile/asdf101/

This would be the profile page for user 'asdf101'

Currently if I type in this url it takes me to the 404 page, I assume its because it is looking for a page called 'asdf101'. How can I fix this?

Upvotes: 1

Views: 72

Answers (1)

Kyle Tripp
Kyle Tripp

Reputation: 79

Answering my own question, this code worked when I added it to functions.php

function add_profile_rewrite_rule($aRules) {
    $aNewRules = array('profile/([^/]+)/?$' => 'index.php?pagename=profile');
    $aRules = $aNewRules + $aRules;
    return $aRules;
}
add_filter('rewrite_rules_array', 'add_profile_rewrite_rule');

Upvotes: 1

Related Questions