Can you try this code:
add_shortcode('portable_hook', function($atts){
ob_start();
$atts = shortcode_atts( array(
'hook_name' => 'no foo'
), $atts, 'portable_hook' );
do_action($atts['hook_name']);
return ob_get_clean();
});
add_action('generate_after_do_template_part',function(){
global $loop_counter;
$loop_counter++;
if ( $loop_counter == 5 ) {
echo do_shortcode('[portable_hook hook_name="after_fifth_post"]');
} else if ( $loop_counter == 9 ) {
echo do_shortcode('[portable_hook hook_name="after_ninth_post"]');
}
});
With this, you’ll have these two hooks:
after_fifth_post
after_ninth_post