Make Author Archive Page URL be a Subdirectory of a Custom Post Type URL

Change custom-post-type in the following to the name of your CPT, both the slug and post_type= in the query vars. Visit your Permalinks Settings page to flush rewrite rules. You could also put this in a plugin and flush rules on plugin activation. function wpa83047_author_rewrite_rule(){ add_rewrite_rule( ‘^custom-post-type/author/([^/]+)/?$’, ‘index.php?author_name=$matches[1]&post_type=custom-post-type’, ‘top’ ); } add_action( ‘init’, ‘wpa83047_author_rewrite_rule’ );

ow to change cutsom page url of wordpress site using htaccess

At first, you shouldn’t use .htaccess directly when working with WordPress. WordPress has powerful rewrite API allowing you to do the stuff from plugins or theme’s functions.php If you need the id=floos on more than one page, consider using rewrite endpoints: function makeplugins_add_json_endpoint() { add_rewrite_endpoint( ‘floos’, EP_PAGES ); } add_action( ‘init’, ‘makeplugins_add_json_endpoint’ ); To determinate, … Read more

wordpress url correction

Copy the index.php and .htaccess file(Just copy it , do not move it ) from myblog directory to root directory. Open index.php file in any text editor and find the following code in the file. /** Loads the WordPress Environment and Template */ require(‘./wp-blog-header.php’); Replace it with the following code and save the file. /** … Read more

How to obfuscate theme directory URLs

Use get_template_directory_uri(): $url = get_template_directory_uri() . ‘/images/myimage.jpg’; This function will always return the correct path to your theme. If you want to hide/shorten that URL, you could use an endpoint, maybe img. The downside is, you load the complete WordPress for each image request. Or use mod_rewrite: RewriteRule ^img/([a-z\d-])\.png /wp-content/themes/my_theme/img/$1.png [L] This will not work … Read more

Localize URL bases

This should cover everything: function wpa_rewite_translate(){ global $wp_rewrite; $wp_rewrite->pagination_base=”pagina”; $wp_rewrite->author_base=”autor”; $wp_rewrite->comments_base=”comentarios”; $wp_rewrite->feed_base=”alimentar”; $wp_rewrite->search_base=”busqueda”; $wp_rewrite->set_category_base( ‘categoria/’ ); $wp_rewrite->set_tag_base( ‘etiqueta/’ ); } add_action( ‘init’, ‘wpa_rewite_translate’ ); Feel free to laugh at my translations, haha. Also, to flush rewrite rules when your theme is activated, add this: function wpa_flush_rewite(){ flush_rewrite_rules(); } add_action( ‘after_switch_theme’, ‘wpa_flush_rewite’ );

Custom url rewriting

[answer updated as wanted] It’s better to hook your function to generate_rewrite_rules so you won’t have fall into infinite loops and flushing rewrite rule on every request. So you can do this: function add_my_rules($wp_rewrite) { $new_rules = array( ‘^cityprofile/\?city=(Sydeny|Melbourne|Brisbane)$’ => $wp_rewrite->preg_index(1) // for 3 cities ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_action(‘generate_rewrite_rules’, ‘add_my_rules’); and … Read more

How to use if($wp_query->query_vars[‘name’] == ‘pagethatdontexist’) without getting a 404? How to suppress 404

You can use an earlier action, request, to do whatever you need. It allows you to modify query variables, or even cancel the entire request without issuing a 404 error: function wpse112929_cancel_request_parsing( $query_vars ) { if ( in_array( ‘pagethatdontexist’, $query_vars ) ) { return array(); } return $query_vars; } add_action( ‘request’, ‘wpse112929_cancel_request_parsing’ ); I used … Read more