Wainsworld Wainsworld - 1 year ago 109
PHP Question

Echo wordpress page title into onsubmit

I have a single contact form the runs through the footer of every page on my site.

I have got the page title to echo out using

but it is appearing before the form rather than in the string.

$html .= sprintf( '<form onsubmit="ga(\'send\', \'event\', \'newsletter\', \'submitted\', \'' . wp_title('') . '\')" %s>', $atts ) . "\n";

It appears like this:

enter image description here

Answer Source

From documentation:

Your code

wp_title( string $sep = '&raquo;', bool $display = true, string $seplocation = '' )

secod parameter determines if the title will be echoed or returned, in Your case you should set $display parameter to false.


$html .= sprintf( '<form onsubmit="ga(\'send\', \'event\', \'newsletter\', \'submitted\', \'' . wp_title('', false) . '\')" %s>', $atts ) . "\n";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download