Set default (auto) slug prefix for Tags

You can use the created_term or the created_{taxonomy} hooks which are fired just after a taxonomy term is created (the second only if it matches the taxonomy). The following will only alter terms in the taxonomy ‘my-taxonomy’. (I believe for the default tags, taxonomy should be ‘post_tag’). add_action(‘created_term’, ‘my_add_prefix_to_term’, 10, 3); function my_add_prefix_to_term( $term_id,$tt_id,$taxonomy ) … Read more

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

The same slug in multiple taxonomies

When you say keyword, do you mean term? I just did a quick test to confirm: I can have the same term, which has the same slug, in both the Category and Post Tag taxonomies, so I assume that custom taxonomies likewise can have terms with the same slug. So, might there be some taxonomy/term … Read more

How to prevent duplicate slugs for wp_insert_post?

If you use wp_insert_post, it should calculate a unique post slug for you. If you don’t use wp_insert_post, try using wp_unique_post_slug. If neither of those are working for you, you could simple try appending -page or to the new page’s post_name (slug) before inserting it. WordPress does its uniqueness check on post slugs at application … 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) ); } }

Determining Slug Before and After Edit

If the post/page was previously published, and you changed the slug when you edited the page, the old slug gets put into the post meta table with the name _wp_old_slug. So you can use get_post_meta( $post->ID, ‘_wp_old_slug’, $single = false ); to retrieve the former slug(s). I see no reason this wouldn’t work with CPTs, … Read more

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