Shortcode is not working in homepage page template (custom front page)

The common way to approach this is to use do_shortcode(). But that’s not an efficient way to do it because it has to run a pretty extensive regex (regular expression) to parse through every single shortcode in your WP install to get to the one you are asking for. See this post for a more thorough explanation.

A better approach is to run the callback function needed directly. But that can sometimes be a challenge – either you have to dig through a lot of code to find it, or it may possibly be in an object class and how do you call that?

J.D. Grimes has provided a good utility function for calling shortcodes this way so that you can get to the direct callback function without having to use do_shortcode(). Add the following function, which you can use for any shortcode instance:

/**
 * Call a shortcode function by tag name.
 *
 * @author J.D. Grimes
 * @link https://codesymphony.co/dont-do_shortcode/
 *
 * @param string $tag     The shortcode whose function to call.
 * @param array  $atts    The attributes to pass to the shortcode function. Optional.
 * @param array  $content The shortcode's content. Default is null (none).
 *
 * @return string|bool False on failure, the result of the shortcode on success.
 */
function do_shortcode_func( $tag, array $atts = array(), $content = null ) {
 
    global $shortcode_tags;
 
    if ( ! isset( $shortcode_tags[ $tag ] ) )
        return false;
 
    return call_user_func( $shortcode_tags[ $tag ], $atts, $content, $tag );
}

Then you can call your shortcode this way:

echo do_shortcode_func( 'mc4wp_form', array( 'id' => 'id' ) );