wordpress change posts archive

Solutions on MaxInterview for wordpress change posts archive by the best coders in the world

showing results for - "wordpress change posts archive"
Rick
07 Oct 2020
1add_action('init', 'post_slug_rewrite');
2
3/* You can change "blog" to any slug you prefer.
4   line 10 and 12.
5*/
6function post_slug_rewrite()
7{
8	$args = objectToArray( get_post_type_object('post') );
9
10	$args['has_archive'] = 'blog';
11	$args['rewrite'] = array(
12			'slug' => 'blog',
13			'with_front' => FALSE,
14	);
15
16	register_post_type('post', $args);
17}
18
19function objectToArray( $object )
20{
21	if( !is_object( $object ) && !is_array( $object ) )
22	{
23			return $object;
24	}
25
26	if( is_object( $object ) )
27	{
28			$object = get_object_vars( $object );
29	}
30
31	return array_map('objectToArray', $object);
32}