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 /

Using page as front page, why does /page/### work?

In WordPress you have 3 main kind of “views”: singular pages archives search “Standard” home page is just a somewhat special archive page, a static front page a somewhat special singular page. When you use the endpoint page in front page url, WordPress internally sets the query variable page to a specific number (would be … Read more

404 redirect based on url

I would use the wp hook, which fires right after the request has been parsed and queried: function wpse_199869_wp( $wp ) { if ( ! is_admin() && is_404() && preg_match( ‘/^bh-job/’, $wp->request ) ) { wp_redirect( home_url( user_trailingslashit( ‘jobs’ ) ) ); exit; } } add_action( ‘wp’, ‘wpse_199869_wp’ ); We make sure it’s a 404, … Read more

Add pagination to a template loaded by query variable

After a bit of digging over the weekend, I found the solution and indeed, it is a rewrite rule with the paged variable added add_rewrite_rule(‘collection/men/page/([^/]+)/?$’,’index.php?post_type=collection&men=yes&paged=$matches[1]’,’top’); Pagination now works in the custom template loaded by query variable. i.e. localhost/sample-site/collection/men/page/2 loads the next page instead of a 404 error

Overwrite WordPress’s URL rewrite not working

WordPress has its own rewriting system in PHP so you can do it both ways If you want to rewrite these url from htaccess, i would only make it rewrite http://www.example.com/newsletter/confirm/token to http://www.example.com/newsletter/?ut=token instead of trying to rewrite http://www.example.com/newsletter/confirm/token to http://www.example.com/index.php?page_id=4058&ut=token And let WordPress handle the page id rewrite. So the htaccess rule would be: … Read more

Rewriting in wordpress url

From this other answer on the WP SE add_action(‘generate_rewrite_rules’, ‘roots_add_rewrites’); function roots_add_rewrites($content) { $theme_name = next(explode(‘/themes/’, get_stylesheet_directory())); global $wp_rewrite; $roots_new_non_wp_rules = array( ‘css/(.*)’ => ‘wp-content/themes/’. $theme_name . ‘/css/$1’, ‘js/(.*)’ => ‘wp-content/themes/’. $theme_name . ‘/js/$1’, ‘img/(.*)’ => ‘wp-content/themes/’. $theme_name . ‘/img/$1’, ); $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules; } TheDeadMedic provided a much better version of this function: function … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)