PHP Script within wordpress theme

I have a php script that I’d like to utilize within my wordpress theme. I’d like to restrict access to the page based on users belonging to particular groups so it’s important to keep it within wordpress for that reason.

I’ve tried at least 9 different plugins and the closest one I could find was a plugin that wrapped the code into a unique shortcode to be placed on page. However, the script wasn’t functioning as it should. Lastly, it’s important that I do NOT display the php code for users to view in page source.

Read More

Can this be accomplished and if so, how?

Thanks so much!

Related posts

1 comment

  1. PHP does not ever display in source, if things are working correctly. PHP executes on the server. If things are working the way they should you never see the PHP source.

    I don’t know what your conditions are for this project, but the most straightforward way to access a script is to make a custom page template for it.

    You would …

    1. create your template,
    2. add your script to that template,
    3. create a page from the backend
    4. and assign that page to the template you created

    The second way to access your script would be to create a shortcode. It sounds like you have already come across this solution but were trying to use a plugin. I expect it was some kind of “execute this PHP” shortcode, which is overly complicated. Creating a shortcode is easy. A bare-bones shortcode would look like:

    function bare_bones_sample_shortcode($atts,$content) {
       return "test simple shortcode";
    }
    add_shortcode('bbss', 'bare_bones_sample_shortcode');
    

    You would then write [bbss] in your post body and “test simple shortcode” should show up. In your case you’d want to put your script in place of that return. The $atts and $content let you do things like `[bbss id="abc"]This is cool content[/bbss]. I don’t know enough about your script to write anything more elaborate though.

    There may be other ways to trigger that script, such as hooking it to something– the_content maybe– but again, without knowing more about the script I can’t really elaborate. You could even access it over AJAX.

Comments are closed.