How to Rewrite the URL

Here I mentioned the url http://localhost/wp/2016/?category_name=cricket now i need to rearrange the url like http://localhost/wp/cricket/2016. here cricket is category name and 2016 is year. Remove the ?Query String Variable not a value of the querystring in the wordpress URl. I tried RewriteRule ^([0-9]{4})/?$/(.+)/([^/]+)/?$ /index.php/$1/?category_name=$2[QSA,L] But Not Working
Category: Web

Per Page Permalink Structure for Page Post Type

I am trying to Re-Write Page URL's so that they END with .htm I was able to do this using... /* Add .htm extension to Page URL Links */ add_action('init', 'htm_page_permalink', -1); function htm_page_permalink() { global $wp_rewrite; if ( !strpos($wp_rewrite->get_page_permastruct(), '.htm')){ $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.htm'; } } /* Remove the trailing slash/ on Pages */ add_filter('user_trailingslashit', 'no_page_slash',66,2); function no_page_slash($string, $type){ global $wp_rewrite; if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){ return untrailingslashit($string); }else{ return $string; } } But then …
Category: Web

Why is WordPress rewriting absolute URLs on staging site to include staging prefix when we manually point them at the live site?

Edited for clarity and to display steps we take to reproduce the issue. Question What would cause absolute URLs on our staging site to prepend the staging site's subdomain to them when saved in the editor? Summary We write pages manually in HTML and CSS on a staging site hosted on SiteGround, save our changes, then test them. However, when we save our work in the editor, they all prepend the staging subdomain we are writing on to each of …
Category: Web

Make the home page's slug visible in the browser's URL bar

Is it possible to show the WordPress home page slug visible in the URL bar? I mean when someone visits my WordPress website home page rather than displaying (considering that my website URL is website.com) "website.com" it must shows "website.com/home-slug" in the browser URL bar. Note: I am using a static page as the home page and my permalink uses "post-name". I am not looking for a way to hide the home slug but a way to make it visible …
Category: Web

custom taxonomy and custom post type url conflict

i am having one serious url issue. there is news custom post type. it's slug is news. News taxonomy slug: news_category News taxonomy url is: http://domain.com/news_category/press-release i want to change the url of the news_category to news news . so url of news taxonomy would be: http://domain.com/news/press-release i tried to rewrite the slug news_category to news but that's creating conflict issue. news shows news url but all the posts of news post type are returning 404 not found News post's …
Category: Web

Custom WooCommerce rewrite rules with comma delimiter

I'm trying to troubleshoot a wide-scale problem. I'd like to rewrite default WooCommerce permalinks for categories, to delimiter as commas. Let's take an example: Brand Model Generation Engine Product The permalink structure I'd like to have: /chip-tuning-Ford /chip-tuning-Ford-Focus /chip-tuning-Ford-MK3-FL /chip-tuning-Ford-MK3-FL-1.5TDCi-75kW /chip-tuning-Ford-MK3-FL-1.5TDCi-75kW-Basic-Box I did this via generate_rewrite_rules action, but currently, we have about 4000 categories and 9000 products, so each combination takes a lot of time and space. All rewrite rules by WP default are saved into one field on the …
Category: Web

flush_rewrite_rules() not working on plugin activation

I am experimenting with creating a simple plugin to create a custom post type named project but am having some trouble with the rewrite rules not been flushed on activation. I have the main plugin file with this function: register_activation_hook( __FILE__, 'Project_Custom_Post_Type::activate' ); Then within my class I have this: public function activate() { flush_rewrite_rules(); } My class has a construct of: public function __construct() { add_action( 'init', array( $this, 'register_post_type' ), 0 ); } I cannot see why it …
Category: Web

Dynamic URL Rewrite for Custom

I have a custom post type called Hotels which I woud like to link to using the below url structure: /{country}/{state}/{hotel-name} I am fetching and inserting posts dynamically, so I do not know the number of countries/states. The Hotel Name is the slug version of the post title. I have been banging my head all day trying to get it to work. The below code works to make the links look correct, but then 404s on all posts: function change_link($permalink, …
Category: Web

Trying to add array of paths to post permalink

Am trying to add custom path to my article posttype so my article path will be www.example/parent-post-1/parent-post-2/the-actual-post i tried to add this code /** * @param $post_link * @param $id * Добавить название категории продукта к ссылке * @return array|mixed|string|string[] */ function wpa_course_post_link($post_link, $id = 0) { $post = get_post($id); if ($post instanceof WP_Post) { $parent = get_field('parents', $post->ID) ?: []; $link = ''; foreach ($parent as $post) { $link .= $post->post_name . '/'; } if ($parent) { $post_link = …
Category: Web

Rewrite URL - insert custom variables as a directory path

I'm trying to re-write permalink structure with my own custom url in WordPress for a Divi Theme "project" I have already changed the "Divi slug" from "project" to "prodotti" so currently, the URL appears like this: http://www.example.com/prodotti/%postname%/ with my custom function function custom_post_name() { return array( 'feeds' => true, 'slug' => 'prodotti', 'with_front' => false, ); } add_filter('et_project_posttype_rewrite_args', 'custom_post_name'); I want to add to these urls a variable, that reside for each post in post_metadata, in order to build a …
Category: Web

returning the currect URL for nested posts

I have a posttype called (article) witch have a meta_key called (parents_ids). So the article can be related to multiple articles. I want to return the currect URL depending on the parent post For example: 1-If the user click on the child-article comming from parent-article-1 i want the url to be example.com/parent-article-1/child-article. 2-If the user click on the child-article comming from parent-article-2 i want to return the url example.com/parent-article-2/child-article
Category: Web

Add %post_id% to slug of custom post type and prevent the "unique slug" thing that WP does?

I have a custom post type called "equipment". I would like the permalink structure to be: example.com/equipment/%post_id%-slug I specifically want it to use a dash and not a slash (i.e. - "id-slug" not "id/slug"). Every possible solution I've found from googling has used slashes and I just can't get it to work with a dash. I also want to prevent WordPress from adding on the additional number if there's two posts with the same title. Example: example.com/equipment/45-awesomeness and example.com/equipment/46-awesomeness-2 I …
Category: Web

How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes '&' to '#038;'?

I use a quick redirects plugin and it's changing my URLs after the fact and thereby breaking some of my links. I never want wordpress to change & to #038;. There is an unwanted solution to turn off all wp_texturize by placing: remove_filter('the_content', 'wptexturize'); I don't want to disable everything, just the & conversion in URLs. I can physically modify wp-includes/formatting.php by commenting out this line, but it didn't work: $content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&$1', $content); I don't want to do …
Category: Web

How can I remove multiple slashes?

Basically that, I have domain.com/ but if I visit domain.com// or with more slashes I would like to remove the extra ones and just leave one of them. I found this but it's not working, I added on the .htaccess file. <IfModule mod_rewrite.c> RewriteBase / RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$ RewriteRule (.*) %1/%2 [R=301,L] </IfModule> Keep in mind I used the homepage as an example, but it can happen on any page, adding extra slashes doesn't break the page but I need …
Category: Web

Url rewriting on custom post with CPT UI plugin

I checked all subjects in forum about this but i didn't found way to resolve my problem. sorry for my english, i'm french.. :) So.. i got a custom post listing ( with template listing pro ) there : http://easycowork.fr/bureau/easy-office-lille/ I created a custom post named service and i display all service associate on listing on the listing single page. When i click on a service, i display his data on the same page with a GET parameter ( the …
Category: Web

How do I add a tag slug to a category URL to filter posts?

I want to add an option to my site to filter posts by one specific tag on the category page and at the same time have a nice URL (no query strings). So something like this: https://example.com/%category%/ - standard category link (currently) https://example.com/%category%/%tag%/ - a page like the above, but displaying posts from a specific category AND tag. Is this possible? If so, how can I achieve this? I would also like to note that for posts I have such …
Category: Web

Use Parent Pages for URL Structure without Landing Page

So this is more a philosophical question than anything, and if I'm asking this in the wrong place, I'm happy to remove the post: What's the best way to use a parent page for structure while keeping that page inaccessible to users? I'm running into two issues: First, I want to use the parent page in the main menu so that I can take advantage of WordPress's current-menu-parent and like classes for styling purposes. I know that normally you can …
Category: Web

Adding /blog in front of single posts (only)

I would like to add /blog in front of the url for a single post: e.g. website.com/blog/news-article -> single article website.com/blog -> blog archive (showing a list of all blogs etc.) Ive tried adding /blog/%postname% as the permalink structure, however it adds it in front of everything, including some custom post types: e.g. website.com/blog/shops/single-shop-page How do I go about adding it in front of posts but nothing else? Thanks in Advance! M
Category: Web

Rewrite nested urls for custom post type

I have a problem with nested permalink. I have a structure of urls like that: Catalog -> Category -> Product My urls are: www.domain.com/catalogs (for archive catalog) www.domain.com/catalogs/%catalog% (for single catalog page with the list of categories) www.domain.com/catalogs/%catalog%/%category% (for single category page with the list of products) www.domain.com/catalogs/%catalog%/%category%/%product% (for single product page) In the WP Backoffice and Frontoffice all url are correct, the only problem that I have is when I visit the product page, for example: www.domain.com/catalogs/catalog-001/category-001/product-001 There I …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.