Okay, I found a way to do it, if someone ever need to create a permalink or change a permalink for a virtual page or a dynamic page, here’s how:
The get_permalink()
, the_permalink()
and get_the_permalink()
functions may be filtered by using the post_type_link
, page_link
and/or post_link
filters, each one of these is for one kind of post.
This is the function I ended up with:
function mytableplugin_rename_permalink($url, $post) {
$table = get_page_by_path('mytablepluginpage');
global $wp;
if ( 'integer' === gettype( $post ) ) {
$post_id = $post;
} else {
$post_id = $post->ID;
}
// check if we are targetting the plugin page
if ( $table->ID == $post_id ) {
$url = home_url( $wp->request );
}
apply_filters( 'mytableplugin', home_url( $wp->request ), get_the_ID(), false );
// Return the value of the URL
return $url;
}
add_filter( 'post_type_link', 'mytableplugin_rename_permalink', 10, 2 );
add_filter( 'page_link', 'mytableplugin_rename_permalink', 10, 2 );
add_filter( 'post_link', 'mytableplugin_rename_permalink', 10, 2 );
I didn’t have to add all the three filters, but I did as to avoid any problems if I ever change the post type of the page in the plugin.
I got the code for making it work from this page and this question
It fixed the canonical URL, the permalink and the translatePress problems.