How can I set up a secondary permalink structure?

I think I found a solution to this with a function that’s not commonly used: add_permastruct(). This does the trick of what I described above: add_rewrite_tag(‘%page%’,'([^/]+)’, ‘pagename=”); add_permastruct(“abc’,’/abc/%page%/’,false); add_rewrite_rule(‘abc/?$’,’index.php?page_id=6′,’top’); The add_rewrite_tag() defines the pagename value that I want WordPress to lookup. Then add_permastruct() defines my custom structure with that value. The last rule is just … Read more

Rewrite Question Mark in Post Template with URL Parameter for clean URLs

Your should add rewrite endpoint template on theme activation hook and init hook. Also there is some little checks to perform to prevent errors. function sjc_theme_activate(){ sjc_theme_add_rewrite_endpoint(); flush_rewrite_rules(); } //for more info http://codex.wordpress.org/Plugin_API/Action_Reference/after_switch_theme add_action( ‘after_switch_theme’, ‘sjc_theme_activate’ ); function sjc_theme_deactivate(){ flush_rewrite_rules(); } //for more info http://codex.wordpress.org/Plugin_API/Action_Reference/switch_theme add_action( ‘switch_theme’, ‘sjc_theme_deactivate’ ); function sjc_add_query_vars($vars) { $vars[] = ‘template’; … Read more

How to link a PDF file to a category URL

If your theme has an attachment template (attachment.php) and you upload your page/post-specific media items, then you will get a page/post-specific media attachment URL. Suppose you are adding/editing your post/page on Case Study (i.e. cs1), so your post/page URL will be (if post-name permalink structure is enabled): http://example.com/cs1/ If you upload an image or a … Read more

Do rewrites added with add_rewrite_rule() persist after plugin deletion?

Let me say beforehand that when using add_rewrite_rule() nothing is written to the htaccess file. Rewrite rules are stored in the database and handled by WordPress internally on PHP level. TL;DR: Rewrite rules do persist after plugin deletion, but probably not the way you’d expect it. When using add_rewrite_rule these rules are added in the … Read more

Proper way to set up rewrite with Wp

See flush_rules in Codex: Because this function can be extremely costly in terms of performance, it should be used as sparingly as possible – such as during activation or deactivation of plugins or themes. Every attempt should be made to avoid using it in hooks that execute on each page load, such as init. Only … Read more

How to change the displayed URL?

I think you shoud use some .htacess rexrite rules either than relying on the wordpress rewrite functions. It seems more appropriate in your case. Try a rule like this : RewriteRule ^root/([a-zA-Z]+)/([a-zA-Z]+)/$ /root/$2/ [R=301,L] Insert it right after RewriteBase /