Skip to content

Instantly share code, notes, and snippets.

@mbootsman
Last active February 27, 2020 12:43
Show Gist options
  • Save mbootsman/ba43f651a995f353fca3ff8d7bc10483 to your computer and use it in GitHub Desktop.
Save mbootsman/ba43f651a995f353fca3ff8d7bc10483 to your computer and use it in GitHub Desktop.
Custom post type permalink structure with hyphen instead of slash
@remcotolsma
Copy link

remcotolsma commented Feb 27, 2020

Didn't test it, but i like the add_rewrite_rule function for custom rewrite rules:
https://developer.wordpress.org/reference/functions/add_rewrite_rule/

<?php

add_action( 'init', function() {
	add_rewrite_rule(
		'text-(.+)?',
		array(
			'post_type'      => 'post-type-name',
			'post-type-name' => '$matches[1]',
		),
		'top'
	);
} );

@mbootsman
Copy link
Author

Ah good addition, thanks!

Didn't test it, but i like the add_rewrite_rule function for custom rewrite rules:
https://developer.wordpress.org/reference/functions/add_rewrite_rule/

<?php

add_action( 'init', function() {
	add_rewrite_rule(
		'text-(.+)?',
		array(
			'post_type'      => 'post-type-name',
			'post-type-name' => '$matches[1]',
		),
		'top'
	);
} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment