Answers for "wordpress change posts archive"

PHP
1

wordpress change posts archive

add_action('init', 'post_slug_rewrite');

/* You can change "blog" to any slug you prefer.
   line 10 and 12.
*/
function post_slug_rewrite()
{
	$args = objectToArray( get_post_type_object('post') );

	$args['has_archive'] = 'blog';
	$args['rewrite'] = array(
			'slug' => 'blog',
			'with_front' => FALSE,
	);

	register_post_type('post', $args);
}

function objectToArray( $object )
{
	if( !is_object( $object ) && !is_array( $object ) )
	{
			return $object;
	}

	if( is_object( $object ) )
	{
			$object = get_object_vars( $object );
	}

	return array_map('objectToArray', $object);
}
Posted by: Guest on May-17-2020

Browse Popular Code Answers by Language