不使用.HTACCESS
为了这个
它的疯狂,WP将与
-
您的网站将在
.htaccess
... 相反,您需要修改url生成代码:
将此插入functions.php
:
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;
$new_title = isset($_POST[\'new_title\'])? $_POST[\'new_title\'] : null;
$post_name = isset($_POST[\'new_slug\'])? $_POST[\'new_slug\'] : $new_title;
//on first fire, there is not set the "new_slug"
$_POST[\'new_slug\'] = ISSET($_POST[\'new_slug\']) ? $_POST[\'new_slug\'] : slug_modify($post_name);
}
//disable slug beforehand Post Update action (also, in navigation menus and etc...)
add_filter(\'name_save_pre\', \'MyfilterNameSavePre\');
function MyfilterNameSavePre($post_name) {
if (!empty($_POST[\'post_ID\']) || !empty($_POST[\'post_name\']) || !empty($_POST[\'post_title\']) ){
// check that we\'re dealing with a product, and editing the slug
$post_id = !empty($_POST[\'post_ID\']) ? intval($_POST[\'post_ID\']) : 0;
$new_slug = !empty($_POST[\'post_name\']) ? $_POST[\'post_name\'] : $_POST[\'post_title\'];
//if got from new post
if ($post_id && !empty($_POST[\'_wp_http_referer\']) ) { if (stripos($_POST[\'_wp_http_referer\'],\'wp-admin/post-new.php\')!==false) { $post_name = slug_modify($new_slug); $_POST[\'post_name\']=$post_name;} }
}
return $post_name;
}
//disable slug on any update
add_filter(\'wp_insert_post_data\', \'myappend_slug\', 3); function myappend_slug($dataaaaaa) {
if (!empty($_POST[\'_wp_http_referer\'])) {
if (stripos($_POST[\'_wp_http_referer\'],\'wp-admin/post-new.php\')!==false) {
$dataaaaaa[\'post_name\']=slug_modify( (!empty($_POST[\'post_name\']) ? $_POST[\'post_name\'] :$dataaaaaa[\'post_title\']) );
}
}
return $dataaaaaa;
}
function slug_modify($slg) {return str_replace(\'-\',\'+\',$slg);}