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 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

How to change ?lang=cn into /cn/

Set permalink to (Post Name) or http://www.example.com/[blog_name]`/%post_id%/%postname%/` Add following code to functions.php of your theme: add_filter ( ‘alias_rule’, ‘xili_language_trans_slug_qv’ ) ; function xl_permalinks_init () { global $XL_Permalinks_rules; if (class_exists(‘XL_Permalinks_rules’) ) { $XL_Permalinks_rules = new XL_Permalinks_rules (); add_permastruct ( ‘language’, ‘%lang%’, true, 1 ); add_permastruct ( ‘language’, ‘%lang%’, array(‘with_front’ => false) ); } }

WP Login forms action URLs displayed as pretty URLs in browser (ex with Restore Password)

Step 2. However, when I submit an un-matching password, the form is redisplayed and URL is now http://example.com/wp-login.php?action=resetpass&key=xyz&login=zyx. Notice, that action has changed. When I attempt this with an invalid key I get redirected to http://example.com/wp-login.php?action=lostpassword&error=invalidkey. Anyway, the infinite loop is occurring because you are the condition in_array( $action, array(‘rp’, ‘resetpass’) ) remains true for … Read more

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