Viewing 1 replies (of 1 total)
  • Thread Starter denniskoster

    (@denniskoster)

    Solved this problem with the ‘wpseo_canonical’. Marking as resolved. Code:

    // CANONICAL URLS FOR ARCHIVES
    function wpseo_set_archive_canonical( $canonical ) {
    	// Don't change the canonical url for these post types / taxonomies
    	$exclude_posttypes = array('link','inkoopsoftware','videos');
    	$exclude_taxonomies = array('functiesoort','branche','organisatiecategorie');
    	// Check whether the canonical URL should be changed
    	if ( is_archive() && !in_array(get_post_type(),$exclude_posttypes) && !in_array(get_queried_object()->taxonomy,$exclude_taxonomies) && !is_search()) {
    		// Get the permalink of the first post
    		global $post;
    		$attachment = get_post( $post->ID );
    		$parent_post_id = $attachment->post_parent;
    		$canonical = get_permalink( $parent_post_id );
    	}
    	return $canonical;
    }
    add_filter( 'wpseo_canonical', 'wpseo_set_archive_canonical' );
Viewing 1 replies (of 1 total)
  • The topic ‘Canonical url templates’ is closed to new replies.