dimanche 5 juin 2016

Echo WordPress post featured image URL inside Javascript

I am trying to echo WordPress post featured image URL inside JS file.

To fetch featured image from post:

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?><img src="<?php echo $url ?>" />

I have embedded the above code inside the below JS file.

var fapDom = '<div id="fap-wrapper" class="'+(options.wrapperPosition == 'top' ? 'fap-wrapper-top' : 'fap-wrapper-bottom')+' mjv-playlist-bg" style="'+options.wrapperPosition+': 0; height: '+totalHeight+'px;"><?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?><img src="<?php echo $url ?>" /><div id="fap-main" style="color:'+options.mainColor+';"><div id="fap-wrapper-switcher" style="background: '+options.wrapperColor+'; border-color: '+options.strokeColor+'" class="fap-'+options.wrapperPosition+'"></div><p id="fap-init-text">Creating...</p></div></div>';

But this is not working. PHP code not working inside the JS file, so is it possible to fetch the WordPress post featured image URL which is compatible to insert in the place of PHP code.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire