Support » Fixing WordPress » Running PHP in a post URL?

  • I’m trying to figure out how to run php inside a url in a post. I have sucessfully run PHP in a post with the help of:
    But I cannot run PHP inside of a URL.

    For example, if I were to put this in one of my posts:
    <a href="<?php echo $_GET['x']; ?>&pg=1">Link Here</a>
    It malfunctions and messes up both the url and surrounding code.

    I have tried it with the plugin:
    <a href="<phpcode>echo $_GET['x'];</phpcode>&pg=1">Link Here</a>
    And that does not work either.

    It is not the php command that is causing the trouble (I have used the exact code outside of the posts fine), it is because WP is doing something to the posts and I can’t figure out how to remedy it. Both of the popular PHP plugins for WP did not work for this.
    Otherwise the plugins work fine, but when you throw a URL in there something happens.

    I would appreciate any insight on this issue.
    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Use the RunPHP or PHPExec plugins.

    I have tried both. They both work in regular post text but neither seem to work inside hrefs.

    I paid a PHP guru look at it and he came up with this solution. Here’s How you do it:

    1. Install and activate the PHPExec plugin:

    2. Using PHP echo the entire <a>, and enclose that <a> in the PHPExec tags (<phpcode>, </phpcode>)

    So for example, if I wanted to make a link to<?php echo $_GET['x']; ?>&pg=1 using the link text Link Text then I would put this in my post:

    <phpcode><? echo "<a{$_GET['x']}&pg=1>Link Text</a>" ?></phpcode>

    I could also use regular HTML for the link, as well as an <img> as long as there are no quotes. Use single quotes. For example, to link to that same page using the image pic.jpg I would put this in my post:

    <phpcode><? echo "<a{$_GET['x']}&pg=1><img src=pic.jpg></a>" ?></phpcode>

    Hopefully this helps those of you that were having a hard time with this as well. Cheers.

    Makes sense. Thanks for sharing your hard-earned wisdom with all the rest of us! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Running PHP in a post URL?’ is closed to new replies.