for my google event tracking, I need to have the Page Title in WordPress of the current site within a jquery function.
There are many ways to get the title with php, but I´m not really shure, that it is the best way.
Thank you, Cheers Marten
for my google event tracking, I need to have the Page Title in WordPress of the current site within a jquery function.
There are many ways to get the title with php, but I´m not really shure, that it is the best way.
Thank you, Cheers Marten
You must be logged in to post a comment.
Depending on how you generate this page title, you need to pass this through to your JS script.
You can do this with
wp_localize_script()
http://codex.wordpress.org/Function_Reference/wp_localize_script
So after you have enqueued the script you can then pass parameters through.
You can then use it in your JS file like this:
just use:
depending on your setting you want to strip out the blog name out of it
First, you’ll need to get the title in PHP:
Include your javascript file:
Then you need to send the $title variable to your javascript file using wp_localize_script():
Now you have access to the site_title in your javascript file by doing so:
Jquery
javascript
or