function node_wp($post_ID) {
global $post;
$post_title = get_the_title( $post_ID );
$post_url = get_permalink( $post_ID );
$json = array(
'title_post' => $post_title,
'url' => $post_url
);
$data = json_encode($json);
$server_url = get_option('$node_server_url_op');
?>
<script src="<?php echo $server_url; ?>"></script>
<script type="text/javascript">
var socket = io.connect('<?php echo $server_url; ?>');
socket.on('connect', function(){
socket.emit('adduser');
socket.emit('sendchat', '<?php echo $data; ?>');
});
</script>
<?php
}
add_action('publish_post', 'node_wp');
When running my script I get this:
Warning: Cannot modify header information - headers already sent
Can you tell me how to properly add Javascript?