8

I use WordPress as a CMS.

I need to show page instead of category when they have same slug.

  • I have category called "vertical machining centers" with the slug "vertical-machining-centers"

This category is ranking in the second page in google and I want to optimize more. So I create a page..

So as you see the page and the category have the same slug.

When I write www.xx.com/vertical-machining-centers , the category page is opening, I also check with it monkeyman-rewrite-analyzer it shows that category slug is higher rank.

I need to make wordpress to show the page instead of category when they have the same slug.

Is there any plugin or any way to do that without writing code.

Thanks....

2 Answers 2

13

You will need to enable verbose page rules, which make sure that all pages are explicitly defined (instead of using a generic rule). But in addition to that, you need to move these page rules above the taxonomy rules. This is a fairly recent change, I believe it was between 3.0 and 3.1.

I explain how to do this in this answer to a very related question. Together, it is this code:

add_action( 'init', 'wpse16902_init' );
function wpse16902_init() {
    $GLOBALS['wp_rewrite']->use_verbose_page_rules = true;
}

add_filter( 'page_rewrite_rules', 'wpse16902_collect_page_rewrite_rules' );
function wpse16902_collect_page_rewrite_rules( $page_rewrite_rules )
{
    $GLOBALS['wpse16902_page_rewrite_rules'] = $page_rewrite_rules;
    return array();
}

add_filter( 'rewrite_rules_array', 'wspe16902_prepend_page_rewrite_rules' );
function wspe16902_prepend_page_rewrite_rules( $rewrite_rules )
{
    return $GLOBALS['wpse16902_page_rewrite_rules'] + $rewrite_rules;
}
5
  • JAn , Thank you for your answer. I will try it tomorrow on a live site. Is there any plugin that can change the order page or taxonomy rules. what do you mean "enable verbose page rules, which make sure that all pages are explicitly defined (instead of using a generic rule)." What is explicitly defined page? our pages are add using admin panel with no coding.
    – sahin
    Jul 10, 2011 at 17:57
  • The code in my answer switches the page and taxonomy rules, so you can use that. It also enables verbose page rules, which are a bit hard to explain in a comment, maybe you can find another question on this site that explains them (or create a new question for it, it's an interesting one).
    – Jan Fabry
    Jul 10, 2011 at 20:28
  • thanks, is there any plugin that can do what you do????
    – sahin
    Jul 11, 2011 at 16:10
  • This solution worked very well with subpages under a parent page that were conflicting with a custom post type created by this with the slug by the same name the locations plugin by gold plugins: wordpress.org/support/topic/… Oct 13, 2016 at 19:22
  • This solution helped where a customer website had problem with child pages that all showed 404 errors - The matched rewrite rule pointed to attachments and that made a lot of problems. Including this fix helped with that, much appreciated - I need to dive deeper in to this, thanks :-) Apr 2, 2018 at 22:46
1

i'd the same problem as you.

My fix was that one, but for my case i'm using Visual Composer in page creation. That's important 'cause my method will port only the content part of the page.

Instead of changing the priority, i changed the category template for that category!

So.. create the page that you want to set as the category and take note of the ID (for example 86292).

If your category has ad ID (as example 35), you can create a custom category template by copying the archive.php and renaming it to category-35.php.

Inside.. delete every blogloop and set this as the content:

    $p = get_post(86292); 
    echo do_shortcode($p->post_content);

Now every change you made to the post (that can stay as draft) will be reflected on the category :D

One or two notes...

Any custom infos (as SEO, custom css, etc) will NOT BE PORTED! Only the editor content.

If you want to set any custom css, you've to use the tag inside the category-x.php .

1
  • It will be so great to have plugin does prioritizes same slugs to show page, post or category or tag
    – sahin
    Jan 19, 2016 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.