Incorrect Default Permalink
-
It seems when created a new post the title is defaulting to ?p=XXXX, even though the permalink structure is set to %postname% in the backend.
One fix I came up with that seems to resolve it is by adding the following to
custom_permalinks_get_sample_permalink_html()
:if(!empty($new_title)){ $permalink = get_sample_permalink($post->ID, $new_title, $new_slug)[1]; }
Here is the full method:
function custom_permalink_get_sample_permalink_html($html, $id, $new_title, $new_slug) { $permalink = get_post_meta( $id, 'custom_permalink', true ); $post = &get_post($id); if(!empty($new_title)){ $permalink = get_sample_permalink($post->ID, $new_title, $new_slug)[1]; } ob_start(); ?> <?php custom_permalinks_form($permalink, ($post->post_type == "page" ? custom_permalinks_original_page_link($id) : custom_permalinks_original_post_link($id)), false); ?> <?php $content = ob_get_contents(); ob_end_clean(); if ( 'publish' == $post->post_status ) { $view_post = 'page' == $post->post_type ? __('View Page') : __('View Post'); } if ( preg_match("@view-post-btn.*?href='([^']+)'@s", $html, $matches) ) { $permalink = $matches[1]; } else { list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); if ( false !== strpos($permalink, '%postname%') || false !== strpos($permalink, '%pagename%') ) { $permalink = str_replace(array('%pagename%','%postname%'), $post_name, $permalink); } } return '<strong>' . __('Permalink:') . "</strong>\n" . $content . ( isset($view_post) ? "<span id='view-post-btn'><a href='$permalink' class='button' target='_blank'>$view_post</a></span>\n" : "" ); }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Incorrect Default Permalink’ is closed to new replies.