I have a wordpress site. Under single.php
, I have the following body
tag
<body <?php body_class(); ?> onLoad="func(<?php echo $thePostID?>);" >
Reading articles on the web made me convinced of avoiding inline CSS and inline javascipt. So I made a restructuring of my site so that styles and scripts are contained now in external files. Except for this line of code since it really need the post id
and I dont know how can I retrieve it outside of single.php.
Your usual help is appreciated.
Use attributes:
You can then write
Just call it in a script, or document.onload...
It's totally acceptable to write javascript inside script tags. Even though it's not in an external file, it's outside your html.
i would recommend using wp_localize_script
then in your script simple use.