Log in to support

Adding %portfolio-category% as an option to the portfolio permalink

Landing How can we help? General Feedback & Suggestions Adding %portfolio-category% as an option to the portfolio permalink

Viewing 4 posts - 1 through 4 (of 4 total)
  • Post count: 143
    May 17, 2016 at 5:59 pm #268148

    Dear Support,

    I would like to suggest that you add an option to use %portfolio-category% as a variable inside the portfolio permalink, as it is possible with general blog posts.

    I have long used the following code inside functions.php to get this working. But I think it should be a default feature.

    
    	/* ADD PORTFOLIO CATEGORY SLUG
    	================================================== */
    add_filter('post_type_link', 'swift_portfolo_permalink', 1, 3);
    function swift_portfolo_permalink($permalink, $post_id, $leavename) {
        
        if (strpos($permalink, '%portfolio-category%') === FALSE) return $permalink;
            // Get post
            $post = get_post($post_id);
            if (!$post) return $permalink;
     
            // Get taxonomy terms
            $terms = wp_get_object_terms($post->ID, 'portfolio-category');
            if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
            	$taxonomy_slug = $terms[0]->slug;
            else $taxonomy_slug = 'portfolio-category';
     
        return str_replace('%portfolio-category%', $taxonomy_slug, $permalink);
    }

    Thank you for considering my suggestion.
    Kind regards,
    Simon

    Post count: 27441
    May 18, 2016 at 10:39 am #268272

    Replies only viewable for logged in users

    Post count: 143
    May 18, 2016 at 10:40 am #268273

    Replies only viewable for logged in users

    Post count: 27441
    May 18, 2016 at 10:51 am #268282

    Replies only viewable for logged in users

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register