I would like to include the following code in my functions.php file in WordPress, but am stuck getting the correct format, it’s broken at present.
This is the code I have currently –
<script>
jQuery(document).ready(function($){
if (jQuery('body.default, body.alternative').length) {
twitterFetcher.fetch('<?php echo $redux_demo['divider-twitter-id']; ?>', 'twitter-fetcher-tweet', 1, true, false);
};
});
</script>
Many thanks for any tips
Try to use:
instead of:
You need to wrap
divider-twitter-id
in double quotes, not single quote here.To answer the question of ‘adding js into a PHP file’, You need to echo it:
But to accomplish what you’re trying to do, put in
functions.php
:Then in in
wp-content/theme/js/twitter-fetcher.php
,