help with custom rewrite rules

The part that modifies the blog post URLs/permalinks is in the mandoe_update_post_link() function (which is hooked on post_link), and the part that you need to adjust is this: return home_url( ‘/blog/’ . $post->post_name ); Just change the ‘/blog/’ . $post->post_name to ‘/blog/’ . $post->post_name . “https://wordpress.stackexchange.com/” and the URLs would end with a slash. However, … Read more

Mod_rewritte – remove ?m=1 from url

You don’t really need to do anything (unless you have OCD about such things 😉 ) You are not going to redirect to such address and it will die with time, and even if not, the canonical meta in the header will help google to avoid marking it as duplicate content.

WordPress CPT slug and page slug conflicts

As you don’t need the CPT archvie, the easiest way to use example.com/new-site to open a page, and example.com/new-site/post-slug to open single posts of “new-site” post type, is to declare has_archive => false when registering the CPT: add_action( ‘init’, ‘cyb_register_cpt’ ); function cyb_register_cpt() { $args = array( // ….. ‘has_archive’ => false ); register_post_type( ‘new-site’, … Read more

Rewrite without query parameter

The wordpress “rewrite rules” have a horrible name which do not match what people are expecting it to be. Those are not rules to rewrite or redirect or whatever other things you can do with htaccess, but rules which are used to “rewrite” urls into the relevant WP_Query parameters. Therefor if you have a rewrite … Read more

$wp_rewrite->rules is always NULL

Your rewrite rules aren’t showing up because you’re calling it from functions.php before they’ve been defined on a global level. So, you can either hook into an action or pull the rules directly from the DB. Doing it through a hook: function check_my_rewrites() { if ( is_admin() ) var_dump($wp_rewrite->wp_rewrite_rules()); } add_action( ‘init’,’check_my_rewrites’ ); Otherwise, you … Read more

Using get_query_var() from a plugin

Hook into parse_query instead: add_action( ‘parse_query’, function() { add_rewrite_rule( ‘go/([^/]+)/?$’, ‘index.php?redirect_to=$matches[1]’, ‘top’ ); add_rewrite_tag( “%redirect_to%”, ‘([^&]+)’ );` } ); Reason: init is too early, query_vars haven’t been set yet. wp_head is too late, no can redirect at that point.

FLUSH_REWRITE_RULES – after or before REGISTER_POST_TYPE?

Flushing rules forces them to be rebuilt from whatever is currently registered, so you should register post types before flushing. This is why you must register your post types in a plugin activation hook as well as on init, otherwise your rules won’t exist on subsequent requests if you’re flushing on activation.

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