Copy paste this code in your functions.php

// Create the query var so that WP catches the custom /member/username url
  function userpage_rewrite_add_var( $vars ) {
  $vars[] = 'member';
  return $vars;
  }
add_filter( 'query_vars', 'userpage_rewrite_add_var' );

// Create the rewrites
  function userpage_rewrite_rule() {
  add_rewrite_tag( '%member%', '([^&]+)' );
  add_rewrite_rule(
  '^member/([^/]*)/?',
  'index.php?member=$matches[1]',
  'top'
  );
  }
add_action('init','userpage_rewrite_rule');

// Catch the URL and redirect it to a template file
  function userpage_rewrite_catch() {
  global $wp_query;
 if ( array_key_exists( 'member', $wp_query->query_vars ) ) {
  include (TEMPLATEPATH . '/user-profile.php');
  exit;
  }
  }
add_action( 'template_redirect', 'userpage_rewrite_catch' );

// Code needed to finish the member page setup
  function memberpage_rewrite() {
  global $wp_rewrite;
  $wp_rewrite->flush_rules();
  }
add_action('init','memberpage_rewrite');

function strapboot_add_author_filter() {
  add_filter( 'author_link', 'strapboot_filter_author' );
  } 
add_action( 'wp_head', 'strapboot_add_author_filter' );

function strapboot_filter_author( $content ) {
  return preg_replace( '|/author(/[^/]+/)|', '/' . member . '$1' . '', $content );
  }

Post a Comment