Route subpage to Custom Post Type

I usually struggle with this, however this time I managed it relatively easy. Main reference for this answer is here: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule I’d like to use anything in the below as discipline. /artists/djave_co/anything First of all, I added a “rewrite tag” function custom_rewrite_tag() { add_rewrite_tag(‘%discipline%’, ‘([^&]+)’); } add_action(‘init’, ‘custom_rewrite_tag’, 10, 0); Next, I did print_r($wp_query->query_vars) on … Read more

Permalinks on Windows IIS not working and web.config breaks site – does wordpress not support windows server now, if so how?

Download IIS Rewrite from https://www.iis.net/downloads/microsoft/url-rewrite. Install and restart IIS Then modify the web.config Edit web.config, add the rewrite code. <?xml version=”1.0″ encoding=”UTF-8″?> <configuration> <system.webServer> <defaultDocument> <files> <add value=”index.php” /> </files> </defaultDocument> <rewrite> <rules> <rule name=”Main Rule” stopProcessing=”true”> <match url=”.*” /> <conditions logicalGrouping=”MatchAll”> <add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” /> <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” /> </conditions> <action type=”Rewrite” … Read more

Set parent for custom post type archive rewrite url

First, you need to register the %office% rewrite tag: // First, add the rewrite tag. add_rewrite_tag( ‘%office%’, ‘([^/]+)’, ‘post_type=office_members&office_name=” ); // Then call add_permastruct(). add_permastruct( “office_members’, … ); Then, add the custom office_name arg to the public query vars so that WordPress reads/parses it from the URL: add_filter( ‘query_vars’, function ( $vars ) { $vars[] … Read more

rewrite rule generated with mpdf to a shorter version

ok it was easy, the problem was that to match the left side pattern you have to use $1 not $matches[1], this is the solution /** * Rewrite rules */ add_action( ‘init’, function() { add_rewrite_rule( ‘^invoice_([0-9]+).pdf$’, ‘/wp-content/themes/mysitetheme/invoices/invoice_$1.pdf’, ‘top’ ); } ); UPDATE From the suggestions received in the comments, it is now clear to me … Read more

Add custom path to url to specific pages

If you want to change the permalink structure for all Pages (i.e. posts of the page type), you can use the WP_Rewrite::$page_structure property like so: add_action( ‘init’, ‘wpse_382911′ ); function wpse_382911() { global $wp_rewrite; $wp_rewrite->page_structure=”home/%pagename%”; } Don’t forget to flush the rewrite rules — just visit the permalink settings admin page (wp-admin → Settings → … Read more