0

I would like to use php in a wordpress post. I have installed a plugin that allows php to be used in these tags: [php][/php]

I am trying to create this link:

<a href="http://www.facebook.com/sharer.php?u=http://myurl.co.uk/?affid=[php]global $current_user; get_currentuserinfo(); echo $current_user->user_login;[/php]" title="Share on Facebook" target="_blank"></a>

This code doesnt work, but when I simply post the php on its own like so:

[php] global $current_user; get_currentuserinfo(); echo $current_user->user_login;[/php]

it works.

6
  • 4
    "Doesn't work" is never a sufficient description of the problem. Commented Dec 31, 2011 at 18:53
  • 1
    That's probably dependent on that specific plugin (you didn't mention which) and how Wordpress matches those bbcode-esque tags. Please [flag] your question for moderator love if you want it moved to wordpress.stackexchange.com (likely to get more expert advise there). Commented Dec 31, 2011 at 18:58
  • 1
    Did you add the special tags in HTML or VISUAL view of you WYSIWYG editor? My guess is that it should only work under HTML. Can you CTRL+U and paste the source of the link that "doesn't work"? THx. Commented Dec 31, 2011 at 19:03
  • Sorry the plugin is hitreach.co.uk/wordpress-plugins/allow-php-in-posts-and-pages Commented Dec 31, 2011 at 19:14
  • I've inputted it into HTML and it makes no different. Sorry for the poor description im not very experienced. What I meant by doesnt work is that it just doesnt show up in the post. In fact it removes the sidebar too Commented Dec 31, 2011 at 19:15

1 Answer 1

1

Try the Exec-PHP Plugin:

http://bluesome.net/post/2005/08/18/50/

You can insert the usual php tags instead of short codes, i.e. <?php your code here ?> inside your post and it will work like in a normal php file. I am using it with WP 3.3 and I have no issues with it.

Writing PHP in a Post is difficult as it is not designed to be a code editor. You can write your code in a free editor like Notepad++ and when you are sure you have no syntax errors simply copy-paste it into the post.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.