Changing directory and/or URL structure

@kureikain’s answer looks great, and it probably works really well in a wide variety of circumstances. But for author URLs specifically, there’s a simpler way. Change the author_base, like so: global $wp_rewrite; $wp_rewrite->author_base = “people”; $wp_rewrite->flush_rules(); You should only need to run this once, perhaps on a plugin activation. Updating WordPress should not affect this … Read more

What is the best way to output plugin result in certain url

There are two steps: function my_plugin_rewrite_rule() { global $wp; $wp->add_query_var( ‘show_hello_world’ ); add_rewrite_rule( ‘show-hello-world/?$’, ‘index.php?show_hello_world=1’, ‘top’ ); } add_action( ‘init’, ‘my_plugin_rewrite_rule’ ); That takes care of rewriting. Remember to flush the rewrite rules. Now, your plugin can check for get_query_var( ‘show_hello_world’ ); and load a certain file: function my_plugin_template( $path ) { if ( get_query_var( … Read more

Rewrite category wordpress

You can do this with a rewrite rule from within WordPress. Take a look at the documentation for add_rewrite_rule. Something like this: <?php add_action(‘init’, ‘wpse65855_rewrite’); function wpse65855_rewrite() { add_rewrite_rule( ‘^photos/?$’, // the rule regex ‘index.php?taxonomy=category&term=photos’, // where you want the rule to go ‘top’ // the priority. Make this one go first ); } You … Read more

Change page /2 to /transcript with a Rewrite

The rewrite API won’t redirect – it just “maps” URL structures to query strings – you’ll need to do this yourself. First things first, fix that rewrite rule: ‘episode/([^/]+)/transcript’; // Matches anything that follows transcript, not what we want! ‘episode/([^/]+)/transcript/?$’; // Matches only “episode/name/transcript”, optionally with a trailing slash Now bring in a helper function: … Read more

Custom Rewriting to Plugin with Parameters

This approach should work for you: <?php /** * Plugin Name: Rewrite Shortcode **/ add_shortcode( ‘myplugin’, ‘mp_shortcode’ ); function mp_shortcode(){ return ‘<p>Filter: ‘ . get_query_var( ‘filter’ ) . ‘</p>’; } add_action( ‘init’, ‘mp_rewrite’ ); function mp_rewrite(){ $post_id = 2; add_rewrite_rule( ‘myplugin/([^/]+)/?$’, ‘index.php?p=’ . $post_id . ‘&filter=$matches[1]’, ‘top’ ); add_rewrite_tag( ‘%filter%’, ‘([^/]+)’ ); } ?> I … Read more

How to create the pseudo static rules of the page I created

You need a rewrite rule! First things first let’s get that in place: function wpse_226796_rewrite_rule( $rules ) { global $wp_rewrite; // http://php.net/manual/en/reference.pcre.pattern.syntax.php $regex = ‘postcomment-page/([1-9][0-9]*)-paged-([1-9][0-9]*)\.html’; $query = sprintf( ‘%s?pagename=postcomment-page&postid=%s&paged=%s’, $wp_rewrite->index, $wp_rewrite->preg_index( 1 ), $wp_rewrite->preg_index( 2 ) ); // Push our rule to the top of $rules return array( $regex => $query ) + $rules; } … Read more

Google is indexing wordpress attachment pages

Just add this to your functions.php or plugin. add_action( ‘template_redirect’, ‘attachment_redirect’, 1 ); /** * Redirect any attachment page to their parent with 301 redirection */ function attachment_redirect() { global $post; if ( is_attachment() AND isset( $post->post_parent) AND is_numeric( $post->post_parent ) ) { wp_redirect( get_permalink( $post->post_parent ), 301 ); exit(); } }