fix target creation for public links

fix #11645

PR against stable7 because master is in transition to a different implementation.

cc @PVince81