Andrew Bartel is on the right path, but the link doesn’t quite do what you want.
For static PHP files to access WordPress core functionality you need to add this to the top of the PHP file:
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
(This code is from index.php in WordPress core)
Ideally though, you would want to create a WordPress Page Template in your theme or child theme with the custom PHP code.
Related Posts:
- How to add a new product type on woocommerce product types? [closed]
- Updating WordPress overwriting customization tweaks – strategies?
- How to customize the default HTML for WordPress Attachments
- wp_trim_words() does not trim the_content() in WordPress
- page_template toggle between 2 templates + 2 permalinks for same post
- Make page template that is just an “include” of another?
- Selecting An image from the Media LIbrary on the frontend
- WordPress Template not affecting the working, keeps defaulting to the index.php template
- Recommend an open source, template driven website builder UI that produces a working WordPress site [closed]
- For custom templates, is it better to use `template_include` or `type_template`?
- Create default_content layout template based on post id
- Remove template drop down for certain pages
- How do I add a new template to my site
- How to customize core admin pages within a theme?
- How can I make site-wide content editable, for example footer content
- Query post for ‘selected category’ in archive.php
- Showcase elementor templates
- How to get custom page template being edited in gutenberg editor
- Make custom page look exactly as homepage
- Best practice – pages – ACF or inline coding
- Set Title from Custom Template
- How to hook up search results page to a back-end page?
- How To Load an HTML File As A WordPress Page (With No 301/No Redirect)
- Is there a way to by-pass the pagination function on one custom template?
- Editing a post template
- WordPress archive index page
- How to add custom ‘layout’ buttons to wordpress editor?
- How to create custom layouts and static pages in themes for clients
- Custom Content Page
- Create a Page template selector page
- Creating custom page template
- Force WordPress to load a specific template
- Dynamic Sidebars based on page name
- Translate custom template with WPML
- How To make Custom page of every Category
- why won’t my custom css load with the enqueue method or any other method?
- Conflict between Yoast SEO and my custom theme
- How to add a template – so that i can choose a different menu for some pages
- How can I delete the word `Category:` from page titles? [duplicate]
- How can I add category variable inside posts?
- Why does a custom php code inside a custom template not get executed?
- wordpress custom posts page not showing
- How do I target this page specifically?
- How to use a custom playlist template:
- Still desperate about multiple TinyMCEs in widgets – is there any good solution to this yet?
- Displaying Child Page’s Information
- Getting a jQuery library to work in WordPress & Avada
- Use another theme template in my theme
- Redirect Every Instance of The Author Template Pages to Custom Author Pages
- Allow arbitrary text after page URL
- Taxonomy template by post type
- Best way to create a page outside of the pages list
- Template setting is not saving in wordpress
- Make Terms Under Custom Taxonomy Use Specific Single.php Template
- Custom single page based on which custom page template is selected
- Single page template
- Adding css and js to a blank page created with custom template
- Modifying a local template
- Custom template not working for existing pages [closed]
- How to apply styles to the custom page template
- Create a page for each database table entries
- How to edit the new user email notification template
- How to make custom bulk actions work on the media/upload page?
- What are the current recommended best-practices for comments.php?
- Using WordPress functions on other sites
- Print shortcode in custom action hook not where the shortcode is entered
- simple expandable vertical menu, java script problem
- Custom search page and search by title, content and tag
- Best way to integrate an existing PHP application into WordPress
- How can I use a Tiny MCE editor in my custom Gutenberg block?
- How do I remove a customiser option from a parent theme in a child theme?
- Your thoughts on the interaction with one custom database table from WP?
- Is there a way to override require_once of the main theme on the child theme?
- Make RSS feed only accesible by Mailchimp
- WP custom routing does not work
- Best Practice for Displaying Categorized Posts on Front Page
- Using the same database on another Subdomain
- I tried to change my URL and ended up losing access to my site? I went into general settings and changed both WordPress URL and Site URL
- How do I modify the size of the text in my page titles?
- Remove Customizer Control Choices (Type: Radio Array) using Child Themes
- Grabbing a data from wp_usermeta
- wordpress shortcode not working
- Meta Tags by Meta Box
- What is the best way to setup WordPress for version control and PhpStorm while allowing updates
- Get whole linked with wp_list_pages
- How to activate flash cards
- Transferring theme and imported post attachments
- Personalized Gallery what are my options?
- Trying to use .htaccess to redirect /profile to /login-2?action=profile
- Gender based user avatar
- Javascript Tooltip not fully working on my wordpress page
- How to narrow the area between buttons on Helium theme sidebar? [closed]
- bulk generate wp taxonomy tags from wp title with self php script
- Build custom pdf from users choices
- Show Header When Not In Iframe
- Background setting isn’t applied to entire sidebar height
- Changing a setting in the wp-admin/customize.php reverts CSS styles to parent theme [closed]
- Function to query by custom field and category
- Confused about customising widgets
- Loop display only 5 posts