AMP – Change rel=”canonical” from functions.php [closed]

In general you can deregister the action’s callback, after it’s been registered and then register your own before it’s invoked with do_action( '...' ).

Here’s an example:

// Add your own with later priority, e.g. 11 or wrap it in another later hook:
add_action( 'amp_post_template_head', 'wpse_amp_post_template_add_canonical', 11 ); 

function wpse_amp_post_template_add_canonical( $amp_template ) 
{
    // Remove the unwanted callback:
    remove_action( 'amp_post_template_head', 'amp_post_template_add_canonical' );

    // Modify this new output to your needs:
    printf( 
        '<link rel="canonical" href="https://wordpress.stackexchange.com/questions/266324/%s" />', 
         esc_url( $amp_template->get( 'canonical_url' ) )
    );

}