0

Possible Duplicate:
How to access PHP variables in JavaScript or jQuery rather than <?php echo $variable ?>

i'm practically asking this question:

FB share in new window

There is one thing that's different and that's the reason why the given answer over there doesn't work for me.

I'm using wordpress so my link contains php elements. This means i can't just paste the url into jquery since jquery can't cope with php.

the link is the following:

href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php the_title(); ?>"
Community
  • 1
  • 1
Chris
  • 443
  • 2
  • 6
  • 15

1 Answers1

0

You could define the url and title at the page level, so in index.php it would have something like the following in the element:

<script>
    var fbUrl = "<?php the_permalink(); ?>";
    var fbTitle = "<?php the _title(); ?>";
</script>

And then in your javascript file which needs to be included after the above script block:

 href = href="http://www.facebook.com/sharer.php?u=" + fbUrl + "&t=" + fbTitle;
Sol
  • 1,173
  • 7
  • 8
  • theres a syntax error in your script. you dont need to put echo on the_permalink and the_title since itll automatically outputted – loQ Oct 18 '12 at 13:33