fix target creation for public links

fix #11645

PR against stable7 because master is in transition to a different implementation.

cc @PVince81 
Is that simply an additional safety or is it mandatory for the original fix ? (just for information)