add_filter( 'page_template', 'wpa3396_page_template' ); function wpa3396_page_template( $page_template ) { if ( is_page( 'my-custom-page-slug22' ) ) { echo 'Entra por aqui'; $page_template = dirname( __FILE__ ) . '/template-api.php'; } return $page_template; } register_activation_hook( __FILE__, 'installar' ); function installar(){ $titulo = 'my-custom-page-slug22'; $descripcion = 'Pagina reservada para la api'; $plantilla = ''; // Ej. plantilla-contacto.php. Dejar en blanco si quieres dejar la plantilla de por defecto. //don't change the code bellow, unless you know what you're doing $page_check = get_page_by_title($titulo); $new_page = array( 'post_type' => 'page', 'post_title' => $titulo, 'post_content' => $descripcion, 'post_status' => 'publish', 'post_author' => 1, ); if(!isset($page_check->ID)){ $new_page_id = wp_insert_post($new_page); if(!empty($plantilla)){ update_post_meta($new_page_id, '_wp_page_template', $plantilla); } } }