Support » Plugin: WPAdverts - Classifieds Plugin » Url adjustments

  • Resolved Reobed

    (@reobed)


    I want the urls in the site to present the actual permalink of the advert message

    The url right now is : https://lgv.test.8balls.nl/bike/
    but I want it to represent the value that has SEO value so :
    https://lgv.test.8balls.nl/verloren/amsterdam/bike

    The part verloren/amsterdam/bike
    is already in the title, and if I hover over the Title in the advert is shows :
    [Permanente link : Verloren in Nederland, Amsterdam: Bike ]

    Reason is to get as much SEO value in my url, which should also correspond as much as possible with Title

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    this is not possible in WPAdverts by default, and as far as i know WordPress does not support such links out-of-box as well.

    I did some research and it looks like with some additional custom programming you can create links like that. There is a code snippet which explains how to do that here https://gist.github.com/kasparsd/2924900. You will, of course, need to modify it to use the ‘advert’ post type and advert_location taxonomy.

    You can also use a plugin https://pl.wordpress.org/plugins/custom-post-type-permalinks/, but it looks like it will not allow you to have a permalink scheme exactly as in your example.

    Plugin Author Greg Winiarski

    (@gwin)

    Here is a whole code to convert the permalinks from https://example.com/advert/bike/ to https://example.com/advert/danmark-kobenhavn/bike/

    
    // Add our custom permastructures for custom taxonomy and post
    add_action( 'wp_loaded', 'add_advert_permastructure' );
    function add_advert_permastructure() {
        global $wp_rewrite;
        add_permastruct( 'advert', 'advert/%advert_location%/%advert%', false );
    }
    // Make sure that all links on the site, include the related texonomy terms
    add_filter( 'post_type_link', 'custom_advert_permalinks', 10, 2 );
    function custom_advert_permalinks( $permalink, $post ) {
        if ( $post->post_type !== 'advert' ) {
            return $permalink;
        }
    
        $terms = get_the_terms( $post->ID, 'advert_location' );
    
        if ( ! $terms ) {
            return str_replace( '%advert_location%/', '', $permalink );
        }
    
        $post_terms = array();
        $taxonomy = "advert_location";
        $term = $terms[0];
    
        do {
            $post_terms[$term->term_id] = $term->slug;
            $term = get_term( $term->parent, $taxonomy );
        } while( !$term instanceof WP_Error );
        
        $post_terms = array_reverse( $post_terms );
    
        return str_replace( '%advert_location%', implode( '-', $post_terms ) , $permalink );
    }
    

    The code you can add in your theme functions.php file, after adding it go to wp-admin / Settings / Permalinks panel and click the “Save Changes” button to reset WP router and apply new URL schemes.

    Thanks.
    we’ll give it a try !

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.