WordPress.org

Ready to get started?Download WordPress

Forums

Page permalinks without hierarchy (parents) (11 posts)

  1. kahi
    Member
    Posted 5 years ago #

    Hi,
    I'd like to have permalink structure for Pages instead of default...
    http://example.com/parent-page-slug/page-slug
    this...
    http://example.com/page-slug

    I understand it will be probably necessary to modify some core files.

    I already did one step: WP correctly outputs this permalink structure for pages.

    Problem is the second step - rewriting (?), making the WP understand which page should it serve.

    Much thanks for any advice (token PP donation possible), unfortunatelly, I'm obviously not able to fully understand the process of URL analysis and query building to do it by myself.

  2. studiocodes
    Member
    Posted 5 years ago #

    I have figured out how to do this, just that not yet sure how to include the modifications as a plug-in to make the solution friendly to future WordPress upgrades. Still working on that part...

  3. brianbrandt
    Member
    Posted 5 years ago #

    Studiocodes... could you give some direction on to how you did it... Because I could really need to do the same...

  4. studiocodes
    Member
    Posted 4 years ago #

    Where do you want me to send the fix to, brianbrandt?

  5. laz0rama
    Member
    Posted 4 years ago #

    i'd also be interested in this, if possible. thanks!

  6. madmax1404
    Member
    Posted 4 years ago #

    Hey there are more guys out here searching for it. I'm interested too.

  7. maidanet
    Member
    Posted 4 years ago #

    studiocodes, can you post your fix for this online?
    Or send it to me through my site - http://maida.net/contact.html

  8. pixelhub
    Member
    Posted 4 years ago #

    hi,

    @studiocodes, Have you made any progress with the plugin?

    or if any one has the fix could you post it.

    cheers

  9. Scope
    Member
    Posted 4 years ago #

    Is a plugin neccessary? why not post some code?

  10. pixelhub
    Member
    Posted 4 years ago #

    can you please post the code.

    cheers

  11. studiocodes
    Member
    Posted 4 years ago #

    Hi guys, sorry to have missed this thread for so long.

    If you're still looking for the code to remove parent slugs from the page permalinks, here you go:
    OPEN: /wp-includes/page.php
    FIND AN REMOVE:

    while ($curpage->post_parent != 0) {
    $curpage = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = %d and post_type='page'", $curpage->post_parent ));
    $path = '/' . $curpage->post_name . $path;
    }

    FIND AN REMOVE:

    // A page cannot be it's own parent.
    if ( $page->post_parent == $page->ID )
    return $uri;

    while ($page->post_parent != 0) {
    $page = get_page($page->post_parent);
    $uri = $page->post_name . "/" . $uri;
    }

    Do not forget to save the file and make sure it's updated on the test server. Once you did that, go to the Permalinks manager inside wp-admin panel and hit "Save Changes" once to update the permalink settings.

    Note: use these instructions at your own risk.

Topic Closed

This topic has been closed to new replies.

About this Topic