admin管理员组文章数量:1130349
I have following scenario:
my-domain-name/google
my-domain-name/twitter
I need a custom permalink structure to pass google or twitter to domain_name query variable.
I have tried following code:
add_rewrite_tag('%domain_name%', '([^&]+)');
add_rewrite_rule('^/([^/]*)/?','index.php?domain_name=$matches[1]','top');
But not working
For better example Check this site: I am trying to do the similar
I have following scenario:
my-domain-name/google
my-domain-name/twitter
I need a custom permalink structure to pass google or twitter to domain_name query variable.
I have tried following code:
add_rewrite_tag('%domain_name%', '([^&]+)');
add_rewrite_rule('^/([^/]*)/?','index.php?domain_name=$matches[1]','top');
But not working
For better example Check this site: http://currentlydown/facebook I am trying to do the similar
2 Answers
Reset to default 2I'm not sure if I should assume that you were issuing your examples inside of the init hook, but if not that is the reason they weren't working for you.
So inside functions.php
function sd_rewrite_rules() {
add_rewrite_tag('%domain_name%', '([^&]+)');
add_rewrite_rule('^/([^/]*)/?','index.php?domain_name=$matches[1]','top');
}
add_action('init', 'sd_rewrite_rules', 10, 0);
Then if you wanted to retrieve the query variable to do something with it, you would do something like this in a page template file using the $wp_query global.
$domain_value = $wp_query->query_vars['domain_name'];
Everything you would want to know plus more can also be located by reading all about the Rewrite_API and it has tons of examples of doing other things you might find interesting or relevent.
https://codex.wordpress/Rewrite_API
The problem was solved by just one line of code. I am thankful to @rifi2k for long discussion and proposing different solutions.
Here is the solutions:
Add following code to functions.php
function custom_rewrite_basic() {
add_rewrite_tag('%domain_name%', '([a-z]{1,60}\.[a-z]{2,})');
}
add_action('init', 'custom_rewrite_basic');
Then from permalink settings, select Custom Structure and add newly created tag by only in our case its /%domain_name%/ save settings.
I have following scenario:
my-domain-name/google
my-domain-name/twitter
I need a custom permalink structure to pass google or twitter to domain_name query variable.
I have tried following code:
add_rewrite_tag('%domain_name%', '([^&]+)');
add_rewrite_rule('^/([^/]*)/?','index.php?domain_name=$matches[1]','top');
But not working
For better example Check this site: I am trying to do the similar
I have following scenario:
my-domain-name/google
my-domain-name/twitter
I need a custom permalink structure to pass google or twitter to domain_name query variable.
I have tried following code:
add_rewrite_tag('%domain_name%', '([^&]+)');
add_rewrite_rule('^/([^/]*)/?','index.php?domain_name=$matches[1]','top');
But not working
For better example Check this site: http://currentlydown/facebook I am trying to do the similar
2 Answers
Reset to default 2I'm not sure if I should assume that you were issuing your examples inside of the init hook, but if not that is the reason they weren't working for you.
So inside functions.php
function sd_rewrite_rules() {
add_rewrite_tag('%domain_name%', '([^&]+)');
add_rewrite_rule('^/([^/]*)/?','index.php?domain_name=$matches[1]','top');
}
add_action('init', 'sd_rewrite_rules', 10, 0);
Then if you wanted to retrieve the query variable to do something with it, you would do something like this in a page template file using the $wp_query global.
$domain_value = $wp_query->query_vars['domain_name'];
Everything you would want to know plus more can also be located by reading all about the Rewrite_API and it has tons of examples of doing other things you might find interesting or relevent.
https://codex.wordpress/Rewrite_API
The problem was solved by just one line of code. I am thankful to @rifi2k for long discussion and proposing different solutions.
Here is the solutions:
Add following code to functions.php
function custom_rewrite_basic() {
add_rewrite_tag('%domain_name%', '([a-z]{1,60}\.[a-z]{2,})');
}
add_action('init', 'custom_rewrite_basic');
Then from permalink settings, select Custom Structure and add newly created tag by only in our case its /%domain_name%/ save settings.
本文标签: url rewritingI need a custom permalink for my website
版权声明:本文标题:url rewriting - I need a custom permalink for my website 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749041916a2307268.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论