Support » Plugins and Hacks » Custom Permalinks » [resolved] Default URL not equal wp permanent link configurations

[resolved] Default URL not equal wp permanent link configurations

  • I had this problem, solved, and probably someone may need this code to answer the same problem.

    After installing this plugin, my new posts were no longer obeying the rule stablished at Permanent Links Configuration page: http://site.com/blog/%category%/%postname%/

    I was getting the default wordpress url style: ?p=1234

    To solve this problem, I modified the function custom_permalink_get_sample_permalink_html at custom-permalinks.php file, line 288. See it bellow:

    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);
            // I commented this block of code that used to create the input text box
    	<?php custom_permalinks_form($permalink, ($post->post_type == "page" ? custom_permalinks_original_page_link($id) : custom_permalinks_original_post_link($id)), false); ?>
    	$content = ob_get_contents();
        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);
        // Added this if to ensure the substitution of "no-category" category on permalink ("sem-categoria" is in portuguese, ATTENTION to use your wp language here)
            if ( strpos($permalink, "sem-categoria") ) {
    	        $categories = get_the_category($post->ID);
    	        $firstCategory = count($categories) - 1;
    	        $catSlug = $categories[$firstCategory]->slug;
    			$permalink = str_replace("sem-categoria", $catSlug, $permalink);
            // Here I detect the correct permalink and erase the site_url from it
    	$slugURL = str_replace(site_url()."/","",$permalink);
            // Here I pasted the block of code that I have commented before, changing the $permalink variable by the new $slugURL variable that I created before
    	custom_permalinks_form($slugURL, ($post->post_type == "page" ? custom_permalinks_original_page_link($id) : custom_permalinks_original_post_link($id)), false);
    	$content = ob_get_contents();
    	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" : "" );

    Hope this helps someone.
    Be my guest if you have some doubts. =D


  • The topic ‘[resolved] Default URL not equal wp permanent link configurations’ is closed to new replies.
Skip to toolbar