Okay
  Public Ticket #911805
/portfolio/ URL
Closed

Comments

  •  2
    Dave started the conversation

    Is it possible for links to portfolio pages to not have /portfolio/ included

    so 

    myURL.com/the-thing

    instead of

    myURL.com/portfolio/the-thing

  •  1,558
    Laborator replied

    Hi Dave,

    Add the following code at the end of functions.php file to remove the slugs from your portfolio:

    /**
     * Remove the slug from published post permalinks.
     */
    function laborator_remove_portfolio_prefix_from_link( $post_link, $post, $leavename ) {
    
        if ( 'portfolio' != $post->post_type || 'publish' != $post->post_status ) {
            return $post_link;
        }
    
        $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
    
        return $post_link;
    }
    add_filter( 'post_type_link', 'laborator_remove_portfolio_prefix_from_link', 10, 3 );
    
    /**
     * Some hackery to have WordPress match postname to any of our public post types
     */
    function laborator_get_portfolio_item_without_post_archive_prefix( $query ) {
    
        // Only noop the main query
        if ( ! $query->is_main_query() )
            return;
    
        // Only noop our very specific rewrite rule match
        if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
            return;
        }
    
        // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
        if ( ! empty( $query->query['name'] ) ) {
            $query->set( 'post_type', array( 'post', 'portfolio', 'page' ) );
        }
    }
    add_action( 'pre_get_posts', 'laborator_get_portfolio_item_without_post_archive_prefix' );

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group

  •  2
    Dave replied

    perfect - thanks!

    :)

  •  1,558
    Laborator replied

    You're welcome

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group