Assign Value of Custom Wordpress Post/Page Meta Field to JavaScript Variable -


is there way via lines of javascript assign value of custom meta field in wordpress post/page javascript variable?

in other words, i've got custom meta field in wordpress posts , pages named "customamznsearch". i'd assign value of field javascript variable same name... or different name if need be.

also, added bonus define static value variable if no data available meta field.

this code utilizing "customamznsearch" variable.

<script type="text/javascript"> amzn_assoc_placement = "adunit0"; amzn_assoc_tracking_id = "livcouintheci-20"; amzn_assoc_ad_mode = "search"; amzn_assoc_ad_type = "smart"; amzn_assoc_marketplace = "amazon"; amzn_assoc_region = "us"; amzn_assoc_textlinks = ""; amzn_assoc_linkid = "0c1ce8995df23ae16ec99d3bb32502ec"; amzn_assoc_default_category = "sportinggoods"; amzn_assoc_default_search_phrase = customamznsearch; </script> <script src="//z-na.amazon-adsystem.com/widgets/onejs?marketplace=us"></script> 

this code displayed in enhanced text widget in footer of page. enhanced text widget should capable of supporting text, html, css, javascript, flash, shortcodes, , php.

you can output javascript code php this:

<script> var customamznsearch = "<?php echo addcslashes($customamznsearch, '"'); ?>"; </script> 

or if mean <meta> tags, then:

function getmeta(metaname) {     var metas = document.getelementsbytagname('meta');      (i=0; i<metas.length; i++) {        if (metas[i].getattribute("name") == metaname) {           return metas[i].getattribute("content");        }     }       return ""; }  var twittertitle = getmeta("twitter:title"); 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -