• Hi,

    I’m having a lot of trouble running this script in a PHP snippet (and variations of it, tried everything i could think of)

    could anyone help me ? (get_field is from ACF)

    add_action(‘init’,’fn_concours’);
    function fn_concours() {
    if (in_array(‘Oui’,get_field(‘concours_actif’))){
    echo ‘<script type=”text/javascript”>’;
    echo ‘$(document).ready(function(){
    $(“.menu-item-4336 a”).css(“background-color”,”#cc0000 !important”);
    $(“.menu-item-4336 a”).css(“color”,”#fff !important”);
    });’;
    echo ‘</script>’;
    }
    }

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Temyk

    (@webtemyk)

    Hi,

    Why do you use add_action('init','fn_concours');?

    This code works fine via shortcode in the post and when you run everywhere:

    if (get_field(‘concours_actif’) && in_array(‘Oui’,get_field(‘concours_actif’))){
    echo ‘<script type=”text/javascript”>’;
    echo ‘$(document).ready(function(){
    $(“.menu-item-4336 a”).css(“background-color”,”#cc0000 !important”);
    $(“.menu-item-4336 a”).css(“color”,”#fff !important”);
    });’;
    echo ‘</script>’;
    }
    • This reply was modified 5 years, 8 months ago by Temyk.
    Thread Starter snazzydray

    (@snazzydray)

    Thanks for the reply !

    however, when I try your code, the site breaks…

    going crazy with this code !

    Plugin Support Temyk

    (@webtemyk)

    Excuse me. Why is there quotation marks are replaced by strange characters. Here is the code with normal quotes

    if (get_field('concours_actif') && in_array('Oui',get_field('concours_actif'))){
    echo '<script type="text/javascript">';
    echo '$(document).ready(function(){
    $(".menu-item-4336 a").css("background-color","#cc0000 !important");
    $(".menu-item-4336 a").css("color","#fff !important");
    });';
    echo '</script>';
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Javascript wrapped in php’ is closed to new replies.