Support » Developing with WordPress » How to insert PHP Code into a page that executes it eachtime the page loads

  • Resolved woutertrainer

    (@woutertrainer)


    Hello!

    I’m trying to make channel programming for our live TV channel. I have a MySQL database where all of the shows are stored in including their start and end time. Based on this the script checks whats playing at the moment, and what’s scheduled next to play. Now I’ve tried inserting the PHP code into the page with the “XYX PHP Code” plugin, and that works, but it only reloads it when I republish the page that has the code on it, not really a something you want to do.(you can see the result on the link down below, second image.). Then I tried making my own shortcode via my Custom Functions plugin, but then I get a weird JSON error when publishing the page, and the page looks messed up overall (first image).

    This is my PHP Code for registering the shortcode, (also contains the PHP script to get the stuff out of the MySQL database, yes I know, it isn’t completely functional but I rather get this working first.): https://pastebin.com/fmGVDJSH

    Here are the images:
    https://imgur.com/a/cC0eiev

    Kind regards
    Wouter

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Create a custom page template, then assign a blank page to use this custom page template.

    Inside the custom page template’s PHP file, you have full control to write your own PHP code to do anything PHP can do, without using any plugin or shortcodes.

    Thread Starter woutertrainer

    (@woutertrainer)

    Hello, thanks for your answer. Tho for some reason the plugin did work, and it does refresh when you reload the page. My laptop just didnt work properly yesterday. Its working now šŸ˜€

    Moderator bcworkz

    (@bcworkz)

    WP doesn’t search plugin folders for template files, only the current theme. To force WP to use a plugin template instead of the one WP would normally use from the theme, you can use the “template_include” filter.

    This may not be the problem you encountered. I mention it anyway just in case it is a factor in the trouble you had.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.