You could try moving the script include just above the closing body tag, as the script takes control of the knob element which has not yet been included before the php ifs.
So, put the two lines in the footer right above the </body> line.
Depending on other configs, it may also work better inside the first 'if' block, where the knob is inserted, at the end of those scripts within the if block
So, put the two lines in the footer right above the </body> line.
Depending on other configs, it may also work better inside the first 'if' block, where the knob is inserted, at the end of those scripts within the if block