Home UncategorizedWordPress template get custom parameter with SEO URL

WordPress template get custom parameter with SEO URL

In wordpress development every developer use the template. Its the great feature that provide by the wordpress so that you add the custom design & layout. In the theme development the designer & developer well play with theme template. Various plugin also provide the template functionality so that you can also modify there plugin template also use of the template modification facility.

There is some free & famous plugin like buddypress,woocommerce & ultimate member plugin that provide the template facility. With help of template facility in woocommerce you can modify the product page, product listing page according design. Same case with buddypress there multiple section available. Actually its the social network plugin. There is various sections are there like member profile, activity, message & settings. These section also have same template facility so you can without modification in the plugin you can modify the design of the website.

Now problem came out when you need the get the parameter on the custom template. For example you want create the template for the user profiling. So representing the user profile you need to username or user_id from the URL. With the help of that you can extract the data of the user. With default functionlity of wordpress you cant be get. There is need to custom code. Now i will show you how to access the code.

function add_query_vars($aVars) {
$aVars[] = “user_id”;
return $aVars;
}
// hook add_query_vars function into query_vars
add_filter(‘query_vars’, ‘add_query_vars’);
function add_rewrite_rules($aRules) {
$aNewRules = array(‘user/([^/]+)?$’ => ‘index.php?pagename=user&user_id=$matches[1]’);
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter(‘rewrite_rules_array’, ‘add_rewrite_rules’);

In above code you have seen function add_query_var() that modify default query_var of the wordpress. Then this function add in hook in below line. Now after that work you have modify the wordpress default query now need to get the parameter in our template so code after that code paste in the template or in the funtions.php with all code. then you will be get the parameter on our template.