Pretty URLs or permalinks for attachments

here a simple WordPress rewrite rule to get the job done: add_action(‘generate_rewrite_rules’, ‘attachment_rewrite_rule_14924’); function attachment_rewrite_rule_14924($wp_rewrite){ $new_rules = array(); $new_rules[‘attachment/(\d*)$’] = ‘index.php?attachment_id=$matches[1]’; $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } just add this code to your theme’s functions.php file and save. *note: the index.php is regardless of your existing URL structure.

custom htaccess rewrite rule for page

You can do this with WordPress’ built-in rewrite system. function add_video_rewrite() { add_rewrite_tag(“%video_id%”, ‘([^/]*)’); add_rewrite_tag(“%video_src%”, ‘([^/]*)’); add_rewrite_tag(“%video_title%”, ‘([^/]*)’); add_rewrite_rule(‘^video/([^/]*)/([^/]*)/[^/]*)’, ‘index.php?pagename=video&video_id=$matches[1]&video_src=$matches[2]&video_title=$matches[3]’, ‘top’); } add_action( ‘init’, ‘add_video_rewrite’ ); Didn’t test it, but I think this should work. What is does is first adding tags that you can use in your template (get_query_var(video_id)). Then add a rewriterule that … Read more

Rewrite rules goes away

properties_add_rewrite_rules should be hooked to init so it runs on every request. Rules can be flushed at any time- loading the permalinks settings page calls flush_rewrite_rules, and your rules weren’t added on that request, so they disappear.

Custom Permalinks for Custom Post Types and Taxonomies

Here’s the method I use to get what you’re trying to achieve. First, register your location taxonomy: register_taxonomy( ‘location’, array( ‘business’ ), array( ‘rewrite’ => array( ‘slug’ => ‘business-location’ ) ) ); Next, register the business post type. The important bit to note here is the inclusion of the %location% rewrite tag in the slug. … Read more

Pass parameter to custom post type single while keeping clean url

you can add this parameter in URL with this code to put after registering the custom post type : add_rewrite_tag(‘%location%’, “([^&]+)”); $slug = get_post_type_object(“services”)->rewrite[“slug”]; $query_var = get_post_type_object(“services”)->query_var; add_rewrite_rule( “$slug/([^&]+)/([^&]+)$” , “index.php?$query_var=\$matches[1]&location=\$matches[2]” , “top” ); after adding this in your plugin, you need to flush rewrite rules once : https://codex.wordpress.org/Function_Reference/flush_rewrite_rules then you can read the location … Read more

Custom comments

$args = array(‘post_id’=>get_the_ID(), ‘status’=> ‘approve’); $all_comm = get_comments($args); $per_page = get_option(“comments_per_page”); if(!$per_page) $per_page = 4; $cpage = get_query_var(“cpage”); if(!$cpage) $cpage = 1; if(round(count($all_comm)/$per_page) == 0) $total = 1; else $total = round(count($all_comm)/$per_page); $args_comments = array( ‘base’ => add_query_arg( ‘cpage’, ‘%#%’ ), ‘format’ => “”, ‘total’ => $total, ‘current’ => $cpage, ‘echo’ => false, ‘add_fragment’ => … Read more

WordPress Network on IIS7/SQL Server – Rewrite Issues

This sounds like your domain doesn’t match the cookie being generated. It may not have anything to do with the IP. define( ‘DOMAIN_CURRENT_SITE’, ‘svr-web-csrms’ ); I would expect an actual domain or something, like this. define( ‘DOMAIN_CURRENT_SITE’, ‘subdomain.mysite.tld’ ); I tried to look at your web.config – but it appears that the URL is now … Read more

URL rewrites and pagination

Extending @Stephen Harris’ excellent answer, I would opt for; add_action( ‘generate_rewrite_rules’, ‘my_rewrite_rules’ ); function my_rewrite_rules( $wp_rewrite ) { $wp_rewrite->rules = array( ‘mypageslug/([^/]+)/page/?([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?pagename=mypageslug&user=” . $wp_rewrite->preg_index( 1 ) . “&paged=’ . $wp_rewrite->preg_index( 2 ), ‘mypageslug/([^/]+)/?$’ => $wp_rewrite->index . ‘?pagename=mypageslug&user=” . $wp_rewrite->preg_index( 1 ) ) + $wp_rewrite->rules; } This follows the defacto regex standard … Read more

Mapping multiple URLs to same page

You can use the same answer as the question you referred to (I have answered it). Here’s how you would change to pass the arguments: <?php add_action(‘init’, ‘add_my_rule’); function add_my_rule() { global $wp; $wp->add_query_var(‘args’); add_rewrite_rule(‘test\/finaldestination\/(.*)’,’index.php?pagename=about&args=$matches[1]’,’top’); } ?> Assuming ‘finaldestination’ stays the same always, and the pagename (slug) is ‘about’ (you can change both). Apply your … Read more