Site logo

Archived topic

Hook element PHP fatal error.

5 replies · Started by boaz on October 17, 2021

Viewing posts 1–6 of 6

Hi, im setting up a hook to run some JS code in one of my pages using the hook element,

using this code i setup from an example you gave in one of your answers in the forum.

<?php if ( is_page( [10100584] ) { ?>
       <script>
	    console.log('this a LP run from a hook');
	</script>
<?php } ?>

im getting a PHP Fatal Error: "Uncaught Error: syntax error, unexpected '?>"

hook settings:
wp_head
execute php
run in all pages.

when running just the js code

       <script>
	    console.log('this a LP run from a hook');
	</script>

it runs ok

Thanks

Hi David
i tried this

<?php if ( is_page( (10100584) ) { ?>
       <script>
	    console.log('this a LP run from a hook');
	</script>
<?php } ?>

same result.
PHP Fatal Error: Uncaught Error: syntax error, unexpected '?>

Hi there,

Any particular reason why 10100584 needs to be wrapped in ()?

If it's a single value, you can do it like this:

<?php if ( is_page( 10100584 ) { ?>
       <script>
	    console.log('this a LP run from a hook');
	</script>
<?php } ?>

or like this:

<?php 
if ( is_page( 10100584 ) { 
       echo '<script>
	    console.log('this a LP run from a hook');
	</script>'; 
} 
?>

or do David's recommendation which is basically placing this code:

       <script>
	    console.log('this a LP run from a hook');
	</script>

on a Hook element with set display rule location to a specific page, hooked to wp_footer.

Hi Elvin
this worked

<?php 
if ( is_page_template('template-landing-page.php')) { 
       echo "<script> console.log('this a LP run from a hook');</script>"; 
} 
?>

i guess its the echo that made the difference.
Thanks

No problem. Glad you got it sorted. :D

This archived topic is closed to new replies.