Need to show a certain piece of jQuery in the header of a wordpress site for settings of a plugin. Is it bad practice to use this the php print method to accomplish it? I’m using the following code:
<?php is_page( 'front-page' ); print
"<script>
jQuery(function() {
jQuery('#bannerscollection_kenburns_majestic').bannerscollection_kenburns({
skin: 'majestic',
width: 2530,
height: 1200,
autoHideNavArrows:true,
numberOfThumbsPerScreen:16,
thumbsOnMarginTop:23,
thumbsWrapperMarginTop: 0,
initialZoom: 1,
finalZoom: 1,
});
});
</script>"
?>
EDIT
I ended up using this, which works great.
<?php is_page( 'front-page' ); wp_enqueue_script( 'kbsettings' ); ?>
YOu can try like this
Generally yes, it is bad practice to generate static content in dynamic script, it affects service performance (standalone js cached in user’s browser and php interpreter have to process your lines again and again)
use something like that :
Also, may be you install your plugin in wordpress template of front page ?
You shouldn’t really be printing that many lines. As mentioned, you could use a HEREDOC? Usually, JS in PHP is really only if you need PHP variables in your JS. I don’t see that here?
Why can’t you just load that script instead of printing it?