I need to run wp_enqueue
on javascript files after the DOM has been populated because I need to target a div.
EDIT
I am trying to add the following three scripts:
wp_enqueue_script('react_js', '/scripts/react.min.js' ); wp_enqueue_script('startReact_js', '/scripts/test.js', array('react_js'), '', true); wp_enqueue_script('app_js', '/scripts//App.js', array('startReact_js'), '', true);
The first one will load in the react source code, the second script will create a div on the page for the most parent react component to render in, and the last script will load the most parent react component into said div.
I need the page to load before running the last script b/c React needs a DOM element to render into BUT I can't figure out how to load the script in the footer.
I can successfully add the script to the header. I have read that there is a $in_footer parameter. Every time I try adding my javascript to the footer using the $in_footer param, it disappears entirely from the DOM. Any thoughts?
@Blaine I tried adding the enqueue scripts to my functions.php per your example but I got the white screen of death.
function addScriptsForEducatePage(){ if(is_page(5274)){ wp_enqueue_script('react_js', '/scripts/react.min.js' ); wp_enqueue_script('startReact_js', '/scripts/pages/test.js', array('react_js'), '', true); wp_enqueue_script('app_js', '/scripts/pages/build/App.js', array('startReact_js'), '', true ); } return; } add_action('wp_enqueue_scripts', 'addScriptsForEducatePage')
Any thoughts?
$
is_page( 5274 )
instead ofpage_id
. You're also missing a semicolon afteradd_action()
. With those aside, your code snippet works for me.wp_footer()
function in the footer?