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.
Can this be accomplished and if so, how?
Thanks so much!
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 …
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:
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 thatreturn
. 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.