Home / Archive / Dynamic Category Mautic Forms.
Duplicate Snippet

Embed Snippet on Your Site

Dynamic Category Mautic Forms.

Code Preview
php
<?php
<?php
add_shortcode( 'dynamic_mautic_form', 'potentsky_render_category_form' );
function potentsky_render_category_form() {
    // Default fallback form ID if no category matches (e.g., standard newsletter form ID 4)
    $form_id = 4; 
    // Check if we are viewing a single post or an archive category page
    if ( is_single() || is_category() ) {
        if ( has_category( 'ai-deployment' ) || is_category( 'ai-deployment' ) ) {
            $form_id = 3;
        } elseif ( has_category( 'automation-tools' ) || is_category( 'automation-tools' ) ) {
            $form_id = 2;
        } elseif ( has_category( 'infrastructure-vps' ) || is_category( 'infrastructure-vps' ) ) {
            $form_id = 1;
        }
    }
    // Output the clean, non-blocking Mautic tracking script asynchronously
    return '
    <script type="text/javascript">
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.async = true;
        script.src = "https://potentsky.com' . $form_id . '";
        document.currentScript.parentNode.insertBefore(script, document.currentScript);
    </script>';
}

Comments

Add a Comment