I was wondering if we can trigger a PHP file on every WordPress post or page if a certain condition is met. Let me detail what I want.

  1. Can we write a simple PHP script that will be automatically loaded on every WP post and page. Once loaded, the script should scan the HTML and if it finds a specific DIV tag with the ID myID it should trigger another PHP file (let's say script.php).

  2. Once the target PHP file has been triggered or executed, the target PHP file (script.php) should be able to automatically fetch the URL of the post or page that triggered the file and store it in a variable.

Any ideas??


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.