WordPress.org

Support

Support » How-To and Troubleshooting » Get Page or Post ID from JavaScript

Get Page or Post ID from JavaScript

  • I want to get a Post id from a javascript function in the post editor. I tried this code, but does not work for me:

    <script>
    function get_post_content(){
       return document.getElementById("post-"+id).innerHTML;
    }
    </script>
    
    <a href="#" onclick="get_post_content(<?php the_ID(); ?>);">Next</a>

    Thank you in advance.

Viewing 1 replies (of 1 total)
  • You haven’t included any parameter in get_post_content(){ ...;
    this should work better: get_post_content(id){ ...

Viewing 1 replies (of 1 total)
  • The topic ‘Get Page or Post ID from JavaScript’ is closed to new replies.
Skip to toolbar