I need to be able to insert some PHP into an external .js file. Is this possible? I have created a slider using basic slider and need to have the page titles as markers at the top of the slider.
This is the code the .js file uses to generate the markers currently.
var slidenum = key + 1,
var marker = $('<li><a href="#">'+ slidenum +'</a></li>');
I need to replace ‘+ slidenum +’ with the WordPress function ‘get_title’. Can this be replaced with php?
You can define JS variables in your php files, then use those variables in your external js.
for example, in one of your PHP files, you can add:
And for your question:
the_title() reference: http://codex.wordpress.org/Function_Reference/the_title
Update – The Loop:
When your loop is over then you add the javascript part