Skip to content

Instantly share code, notes, and snippets.

@jmslbam
Created January 4, 2012 09:21
Show Gist options
  • Save jmslbam/1559261 to your computer and use it in GitHub Desktop.
Save jmslbam/1559261 to your computer and use it in GitHub Desktop.
Custom Post Type Archive with WPML
<?php
/* Template Name: News Archive */
?>
<?php
include('archive.php');
?>
<?php
/* don't forget to put these in your functions.php */
function add_rules($wp_rewrite) {
$new_rules = array(
'news/([^/]+)/?$' => 'index.php?post=' . $wp_rewrite->preg_index(1),
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'add_rules');
function filter_cpt_link($str) {
if ( ICL_LANGUAGE_CODE == 'en' ) {
$str = preg_replace('|/actu/|', '/news/', $str);
}
return $str;
}
add_filter('post_type_link', 'filter_cpt_link');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment