1

I'm trying to modify the header in a theme for two specific custom post type. The header for all theme page is output from this code:

<script>
        jQuery(function($){

        $('.parallax-window').parallax({imageSrc: '<?php echo  $ilgelo_options['ilgelo-parallax-image']['url'];?>'});
        });
</script>

I've tried to put my condional code:

<?php if ( is_singular( array( 'rivista', 'rivista-trimestrale' ) ) ) {
    <script>
        jQuery(function($){

        $('.parallax-window').parallax({imageSrc: '<?php echo  $ilgelo_options['ilgelo-parallax-image']['url'];?>'});
        });
    </script>
} else {

<script>
        jQuery(function($){

        $('.parallax-window').parallax({imageSrc: 'STYLESHEETPATH."/img/header-rivista.jpg"'});
        });
    </script>
    } 
?>

but I get a syntax error '<' and I can't understand why. Could someone help me please? Thanks.

2
  • Hi, can you please add the exact error output to your question?
    – Johansson
    Commented Apr 3, 2017 at 14:28
  • Parse error: syntax error, unexpected '<' in /homepages/18/d657484804/htdocs/clickandbuilds/DirittiComparati/wp-content/themes/journey-child/template/header/header-style4.php on line 17 *** Line 17 is where I have : <script> Commented Apr 3, 2017 at 14:29

1 Answer 1

1

It seems that you have forgotten to use <?php and ?> properly. Remember to open and close the php tag like the following:

<?php if ( is_singular( array( 'rivista', 'rivista-trimestrale' ) ) ) {?>
    <script>
        jQuery(function($){

        $('.parallax-window').parallax({imageSrc: '<?php echo  $ilgelo_options['ilgelo-parallax-image']['url'];?>'});
        });
    </script><?php
} else { ?>

<script>
        jQuery(function($){

        $('.parallax-window').parallax({imageSrc: 'STYLESHEETPATH."/img/header-rivista.jpg"'});
        });
    </script><?php
    } 
?>
7
  • Tx a lot!!! it partially works: 'cause it sees the conditional output, evenif it doesn't take the link of the image: diritticomparati.themmc.it/rivista/test-articolo-rivista Commented Apr 3, 2017 at 14:37
  • You're welcome. Can you more specific please? I can't quite understand what you mean.
    – Johansson
    Commented Apr 3, 2017 at 14:40
  • Added screenshot belowe :) Commented Apr 3, 2017 at 14:47
  • There might be an issue with your conditional array, since it's outputting a value, but not the right one. Are you sure the names you entered in the array are correct? You might wanna double check that.
    – Johansson
    Commented Apr 3, 2017 at 15:51
  • 1
    Good (tricky) catch, +1. @MonicaMariaCrapanzano: you could've easily avoided this error by using a good text editor, like SublimeText with PHP code checking enabled. or using an IDE.
    – Fayaz
    Commented Apr 4, 2017 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.