Title: Run PHP script on a single page/when called by Javascript
Last modified: March 5, 2024

---

# Run PHP script on a single page/when called by Javascript

 *  Resolved [elliotcullen](https://wordpress.org/support/users/elliotcullen/)
 * (@elliotcullen)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/run-php-script-on-a-single-page-when-called-by-javascript/)
 * Hi there!
 * I am currently transitioning from a massive blob of PHP in my functions.php file
   into multiple separate PHP scripts, as having everything in functions.php was
   slowing the site down (obviously). 
   This works fine, however the scripts are 
   still running on all pages. I need them to only run on a singular page, and the
   code provided in the FAQ did not work:
 *     ```wp-block-code
       if ( ! is_page( richlands' ) ) return;
       ```
   
 * as the scripts do not run (richlands is a slug – do I need the whole link?). 
   Is that the correct format?
 * Another solution if this is a better way is if I could run it from javascript?
   But I am not sure how to do thaat, so would need an example.
 * Thanks in advance!
   Elliot

Viewing 1 replies (of 1 total)

 *  [generosus](https://wordpress.org/support/users/generosus/)
 * (@generosus)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/run-php-script-on-a-single-page-when-called-by-javascript/#post-17549403)
 * Hi [@elliotcullen](https://wordpress.org/support/users/elliotcullen/),
 * You missed a tick mark. Use:
 * `if ( ! is_page( 'richlands' ) ) return;`
 * Cheers 🙂
 * ———-
 * **Reference: **[https://help.codesnippets.pro/en/article/42-can-i-run-my-snippet-on-just-one-page](https://help.codesnippets.pro/en/article/42-can-i-run-my-snippet-on-just-one-page)

Viewing 1 replies (of 1 total)

The topic ‘Run PHP script on a single page/when called by Javascript’ is closed 
to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [page-specific](https://wordpress.org/support/topic-tag/page-specific/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [run](https://wordpress.org/support/topic-tag/run/)

 * 1 reply
 * 2 participants
 * Last reply from: [generosus](https://wordpress.org/support/users/generosus/)
 * Last activity: [2 years, 1 month ago](https://wordpress.org/support/topic/run-php-script-on-a-single-page-when-called-by-javascript/#post-17549403)
 * Status: resolved