/%category%/%post_id%-%postname%
This works great for most of my posts, but there is one category that I want to remove the post_id from so it looks like this /%category%/%postname%
So if the category is CAT and the post-id is 123, then the permalink correctly looks like this:
mydomain.com/cat/123-my-great-cat-post
But if the category is DOG then I do not want the post-id, so it should look like this:
mydomain.com/dog/my-great-dog-post
I understand how to use actions and filters in my functions.php and I think I want to use either generate_rewrite_rules or post_rewrite_rules or add_rewrite_rule and add a new rule to the TOP.
I am honestly confused as how to write the rule though as regex is complicated and I do not understand it.
Any help appreciated.
Thanks
rewrite,rule,rules,generate,add,post,api,regex,generate rewrite rules,add rewrite rule
]]>I am quite unfamiliar to rewrite rules.
What I am trying to do is:
I have created a custom plugin to add “text or phrase” either in the beginning and end of the post title using the the_title filter.
I have created options page for plugin.
Now, I want to modify the Posts’ URL to include the “text or phrase” entered in the Plugin settings.
Please ask, if I lack to explain here.
–e.g–
Settings in Plugin
Before title text: One
After title text: two
Now the Post title will be:
One Post Title Two
This much have been achieved.
Now I want the URL to be:
https://www.example.com/one-post-url-two
Does that make sense?
Any help is heartily appreciated.
Thanks,
Ankit
/service/p2jnd93l
But with my code, the page simply erases the last part of the url and redirects you to
/service/
I have a feeling it’s something extremely obvious… Any ideas what I’m doing wrong?
add_action( "init", "pleasing_permalinks" );
function pleasing_permalinks() {
add_rewrite_tag( '%hash%', '([^&]+)' );
add_rewrite_rule(
'leadership/committees/service/([^/]+)/?$',
'index.php?p=8279&hash=$matches[1]',
'top'
);
}
]]>I need to get a variable appended to the permalink, that should be in a post or custom post type.
No problem getting it when permalink are disabled, this is the code I’m using:
function add_query_vars($public_query_vars) {
$public_query_vars[] = 'fruits';
return $public_query_vars;
}
then I get using
get_query_var('fruits')
The problem is with enabled permalinks.
Using:
add_filter('rewrite_rules_array','mycode_add_rewrite_rules');
function mycode_add_rewrite_rules($rules){
add_rewrite_tag('%fruits%','([^&]+)');
add_rewrite_rule('^([^/]+)/([^/]+)/([^/]+)/?','index.php?pagename=$matches[2]&fruits=$matches[3]','top');
}
I cannot get the variable, then never occurs again 404 error when I add one or more “/” (ex. www.site.com/2012/06/title/first/second/third/)
Could somebody help me resolving this?
Thanks
sth like wordpress/wp-content/themes/mytheme/images.php?v=bla-bla.png
now i would like to set a rewrite rule for that page.
sth like wordpress/images/bla-bla.png
how do i go about this?
i could do it in .htaccess but i would prefer a solution that is implemented in my theme. but as i’m new to mod rewrite and wordpress this task blows my mind…
]]>