How to exclude uncategorized from permalink structure /%category%/%postname%/

I hope this will work for you 😀 function mf_post_link( $permalink, $post, $leavename ) { if( $post->post_type != ‘post’ ) return $permalink; // if no category, the filter is deactivated $cats = get_the_category($post->ID); if( ! count($cats) ) return $permalink; usort($cats, ‘_usort_terms_by_ID’); // order by ID $category_object = apply_filters( ‘post_link_category’, $cats[0], $cats, $post ); $category_object = … Read more

permastruct for custom post type not working in one of four cases

You’re currently placing your rewrite rules in the global scope, which means they execute as soon as your file is loaded, which may be too early. Instead try adding them on the init hook, or rewriting them to use the generate_rewrite_rules filter instead, e.g.: add_action(‘generate_rewrite_rules’, ‘themes_dir_add_rewrites’); function themes_dir_add_rewrites() { $theme_name = next(explode(‘/themes/’, get_stylesheet_directory())); global $wp_rewrite; … Read more

How to change the category in URL for posts in multiple categories?

Similar plugin but compatible to latest wp version 3.5.2 http://wordpress.org/plugins/wp-category-permalink/ This plugin allows you to select a ‘main’ category for your posts, for better permalinks and SEO. It uses the same meta data as the “Hikari Category Permalink” and the “sCategory Permalink”, but it has been rewritten using better and cleaner code. Requires: WP 3.5 … Read more

How to change author base without front

This is the best solution I have come up with but I welcome better ways: function change_author_permalinks() { global $wp_rewrite; $wp_rewrite->author_base=”connect/member”; $wp_rewrite->author_structure = “https://wordpress.stackexchange.com/” . $wp_rewrite->author_base . ‘/%author%’; add_rewrite_rule(‘connect/member/([^/]+)/?$’, ‘index.php?author_name=$matches[1]’, ‘top’); } add_action(‘init’,’change_author_permalinks’);

rewrite get parameter with custom post type

I think it should work. First you need to register your rewrite rule and the parameter: function my_init() { add_rewrite_rule( ‘gallery/(.+?)/?$’, ‘index.php?post_type=gallery&param=$matches[1]’, ‘top’ ); add_rewrite_tag(‘%param%’,'([^&]+)’); } add_action(‘init’, ‘my_init’); Then you can read the parameter value from the query: $param = get_query_var(‘param’); Don’t forget to flush the rewrites. (just view the rewrite settings page to flush … Read more

+ Character in permalink

Per the OP, here is their answer which I separated from the question: I have found a solution for it myself, I’ve used the Custom Permalinks plugin and edited how the special characters are saved in the database. For the people who want to use this, change: add_post_meta( $id, ‘custom_permalink’, str_replace(‘%2F’, “https://wordpress.stackexchange.com/”, urlencode(ltrim(stripcslashes($_REQUEST[‘custom_permalink’]),”https://wordpress.stackexchange.com/”))) ); to … Read more

Passing variables through permalink structure

Solved it! // Register the variables that will be used as parameters on the url function add_my_var($public_query_vars) { $public_query_vars[] = ‘extra_slug’; return $public_query_vars; } add_filter(‘query_vars’, ‘add_my_var’); // Build the rewrite rules, for the extra parameter function do_rewrite() { add_rewrite_rule(‘(accommodation)/[/]?([^/]*)$’, ‘index.php?pagename=accommodation&extra_slug=$matches[2]’,’top’); } add_action(‘init’, ‘do_rewrite’); // The parameter is now accessible get_query_var(‘extra_slug’)