I need the URL's to look like this:
http://localhost/TestProjects/wordpress/gmat/resources etc.
I wrote the below function in my functions.php file of my theme folder
add_action('init', 'custom_rewrite_basic');
function custom_rewrite_basic() {
$rcat='(gmat|gre|sat|cat)';
add_rewrite_tag( '%rootcat%',$rcat);
add_rewrite_rule('^{$rcat}/resources/', 'index.php? pagename=leap_resources&rootcat=$matches[1]', 'top');
}
Related
I need a rewrite rule to catch any URL on my WordPress except my existing pages and posts.
The following code in functions.php rewrites all URLs. How to make this exclude existing WordPress pages/posts?
function custom_rewrite_rule() {
add_rewrite_rule('^.([^/]*)?', 'index.php?page_id=5', 'top' );
}
add_action('init', 'custom_rewrite_rule', 10, 0);
Thanks.
I have a problem with the Rewrite Url Wordpress, I added this code in functions.php on my child theme, and I have already 404 error.
function custom_rewrite_basic() {
add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php?p=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');
Whatever the rule, it does not work
An idea?
thank you
I am working on a wordpress site that is running in a subdomain.
I have added the subfolder on WP .htaccess file to let all the site and permalinks work, so my WP site is running under
http://example.com/subfolder/
Now I need to do the following:
I have this permalink structure that goes to a post:
example.com/subfolder/the-post-permalink
And I need to add a rule that send this URL:
example.com/subfolder/the-post-permalink-category
to:
example.com/subfolder/the-post-permalink?param=category
So the post page displayed will be the same, but I will get a GET parameter with "param" value that was sent in the rewrite rule.
I have tried this with the add_rewrite_rule() method on the functions.php file, but could not make it work. Tried adding or not the subdolfer in the rule.
add_action('init', 'add_htaccess_redirects' ,10, 0);
function add_htaccess_redirects()
{
add_rewrite_rule(
'^subfolder/the-post-permalink-(.*)',
'subfolder/the-post-permalink?param=$matches[1]',
'top'
);
}
and
add_action('init', 'add_htaccess_redirects' ,10, 0);
function add_htaccess_redirects()
{
add_rewrite_rule(
'^the-post-permalink-(.*)',
'the-post-permalink?param=$matches[1]',
'top'
);
}
Any help please?
Thanks.
I am trying to create a custom page in Wordpress with a special URL Rewrite and I am trying the following:
function custom_rewrite_rule() {
add_rewrite_rule('^services/service-in-([^/]*)/?','index.php?page_id=238&location=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule');
However, when I go to domain.com/services/service-in-london/ I just get a 404 message.
I have also tried this manually in htaccess but just get a 404.
Can you please try below code
function custom_rewrite_rule() {
add_rewrite_tag('%location%', '([^/]*)');
add_rewrite_rule('^services/([^/]*)/?$', 'index.php?page_id=238&location=$matches[1]', 'top');
flush_rewrite_rules();
}
add_action('init', 'custom_rewrite_rule');
I am creating a theme by myself in wordpress. But suddenly my functions.php file stop to work. I am enqueuing a stylesheet file. First time it worked. But now its not working. whats wrong with it? (I am new in wordpress) My code is
<?php
function get_external_files(){
wp_enqueue_style('style', 'get_stylesheet_uri()');
}
add_action('wp_enqueue_scripts', 'get_external_files');
You've put get_stylesheet_uri() inside quotes '' turning it into a string instead of a function call... This should work:
<?php
function get_external_files(){
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'get_external_files');