Title: Get php variable in functions.php &amp; echo it in theme template inside JavaScript
Last modified: August 24, 2016

---

# Get php variable in functions.php & echo it in theme template inside JavaScript

 *  Resolved [taghaboy](https://wordpress.org/support/users/taghaboy/)
 * (@taghaboy)
 * [11 years ago](https://wordpress.org/support/topic/get-php-variable-in-functionsphp-echo-it-in-theme-template-inside-javascript/)
 * I’m working in a WordPress template, and I try to echo the variable “**citation_string_to_js**”
   who is in function.php into the JavaScript in my theme footer.php… but it output
   it empty !
 * This is the code i use in **function.php** :
 *     ```
       add_filter( 'citation_string_to_js', 'return_citation_string_to_js' );
       function return_citation_string_to_js( $arg = '' ) {
       return 'YOUR CONTENTS GOES HERE';
       }
       ```
   
 * The JavaScript in Theme template (footer.php) :
 *     ```
       <script type="text/javascript">
       document.getElementById('grid-4').innerHTML = '<? echo apply_filters( 'citation_string_to_js', '' );?>';
       </script>
       ```
   
 * what’s wrong ?
 * Thanks for helping.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [11 years ago](https://wordpress.org/support/topic/get-php-variable-in-functionsphp-echo-it-in-theme-template-inside-javascript/#post-6164261)
 * Your code works fine on my end. Can you temporarily [enable debugging](https://codex.wordpress.org/Editing_wp-config.php#Debug)
   and see if any errors appear? Are PHP short open tags enabled by your hosting
   environment?
 *  Thread Starter [taghaboy](https://wordpress.org/support/users/taghaboy/)
 * (@taghaboy)
 * [11 years ago](https://wordpress.org/support/topic/get-php-variable-in-functionsphp-echo-it-in-theme-template-inside-javascript/#post-6164262)
 * Thanks for your reply,
    Your right, i do a mistake 😉 I use .grid-4 instead of#
   gride-4 I must to sleep hhhhh thanks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Get php variable in functions.php & echo it in theme template inside 
JavaScript’ is closed to new replies.

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [taghaboy](https://wordpress.org/support/users/taghaboy/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/get-php-variable-in-functionsphp-echo-it-in-theme-template-inside-javascript/#post-6164262)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
