How to Disable UNICODE slug?

时间:2014-01-01 作者:T.Todua

我正在用UNICODE插入帖子标题,但我不想用UNICODE UTF8字符保存。相反,我想在slug自动创建之前使用我的标题转换函数:如下所示:

function my_convert($string)
{
$string = str_replace(\'ჲ\',\'a\',$string);
$string = str_replace(\'ძ\',\'b\',$string);
..............
.............
return $string;
}

1 个回复
SO网友:T.Todua

我的解决方案使用3个组合挂钩wp_insert_post_data, wp_ajax_sample-permalink,name_save_pre

  //==================DISABLE GEORGIAN + Russian SLUGS for POSTS================
    //disable slug on any update
    add_filter(\'wp_insert_post_data\', \'myappend_slug\', 3); function myappend_slug($data) {  
        $data[\'post_name\']= slug_modify($data[\'post_name\']);return $data; 
    }
    add_action( \'wp_ajax_sample-permalink\', \'MyajaxSamplePermalink\',1);         function MyajaxSamplePermalink($data) {
        // check that we\'re dealing with a product, and editing the slug
        $post_id = isset($_POST[\'post_id\']) ? intval($_POST[\'post_id\']) : 0;
        $post_name = isset($_POST[\'new_slug\'])? $_POST[\'new_slug\'] : null;
        $new_title = isset($_POST[\'new_title\'])? $_POST[\'new_title\'] : null;
        $chosen = (isset($post_name) ? $post_name : $new_title );
        $_POST[\'new_slug\'] = slug_modify($chosen);
    }
    add_filter(\'name_save_pre\', \'MyfilterNameSavePre\');     function MyfilterNameSavePre($post_name) {
        // check that we\'re dealing with a product, and editing the slug
        $post_id = isset($_POST[\'post_ID\']) ? intval($_POST[\'post_ID\']) : 0;
        $new_slug = isset($_POST[\'post_name\']) ? $_POST[\'post_name\'] : 0;
        if ($post_id) { $post_name = slug_modify($new_slug); }
        return $post_name;
    }

            function slug_modify($slg) {return myFILTERRRRRRR($slg);}

结束

相关推荐

WordPress MultiSite(MU)子目录url/slug/permarink可以更改吗?

我目前正在与WordPress Multisite(MU)、BuddyPress和Commons in a Box(CBOX)合作,围绕一个中心用户群创建一个网站,该网站允许用户组成群组,并创建与其群组相关的“群组博客”。我在这个问题上发布了关于这个确切情况的进一步详细信息here.然而,我想问一个更一般的问题,关于WordPress多站点安装的性质,除了初始站点或网络主页。我的问题是,是否可以更改默认的子目录url结构/文件夹。例如,Multisite当前的默认设置为site。com/blog/sub-