If you are developing a theme, the proper place to put your code in this case if your theme’s functions.php
file. This is the file that is surely going to be run when your website is being accessed.
If you are developing a plugin, you can put your code inside a php file (like foo.php
) and then include/require it in your template, whichever suits your needs.
Don’t save or alter ANY file outside the wp-content
folder, or your plugins. These are going to be overridden by WordPress updates, and have a chance to be identified as malware by some anti-malware plugins/server apps.
You can actually put your code directly inside your plugin’s core file, but i prefer to categorize the functions in case i need to access or modify them quickly later (personal opinion).
Related Posts:
- Verify nonce in REST API?
- Getting $comments outside the comment template
- How wp_ajax_nopriv since WordPress 3.1
- How to use get_option() without any filter?
- How to build a child theme from a react-based parent theme?
- Custom Login and Registration form in Ajax
- Calling a php file from a javascript file in wordpress
- Updating Custom WordPress User Meta Field via REST API
- Load more posts with multiple queries
- Viewing checkout page removes fees from mini cart
- Load MediaPlayerElement after Infinity Scroll loads more posts
- need help with a user-specific custom page template
- How can I display a PHP foreach loop’s answers by AJAX
- WordPress : using AJAX to get posts & Sidebar Content to an external application
- mailchimp integration on a custom footer
- How to get WordPress Theme Customizer options in the REST API?
- POST 429 Error when trying to place more than 20 images into post at once
- How to submit form data in the same page in WordPress without reloading the page?
- Unable to show messages using ‘admin_notices’
- Do i need to use PHP in customizer api?
- Is there anything that Joomla or Drupal can do that can’t be done in WordPress? [closed]
- Any post install tips after installing WordPress 3.0.1?
- Version Control: Entire site or just pieces?
- Customizing the Subject Field in WordPress’ Notification Emails?
- How to move wp-content (or uploads) outside of the WordPress directory
- How to get shortcode working from custom meta field
- How to search in a Custom Field?
- How to override wp-login.php
- Remove Links from Login page
- get_terms return errors
- media_handle_upload weird thing
- Customise search form in the Widget
- Custom Queries – Child Categories not showing up
- Removing label ‘WordPress’ from the title bar
- Schedule cron event from widget
- WordPress Network Feature
- Comments Confusion
- Remove template drop down for certain pages
- Adding all sub-pages to the menu manager
- How can I capture Memberpress user info after signup [closed]
- Hide devices selection from customizer?
- Add options to the “Screen Options” section on the “Menus” editor
- Split Conference WordPress Page in different years
- how to get the categories for a single product in a hierarchical way
- large chunks of text went missing
- How to change popular term checklist title when edit post?
- Save & Publish disabled for two dimensional array Customizer
- Deep customization of wp-login.php
- Custom CSS at Appearance > Edit CSS is missing after update [closed]
- How to store page visit counts?
- Load File (Function & Variable Value) from Child Theme
- Featured Image If Else Condition
- WordPress noob, assign custom stylesheet using @import or if? Didn’t work for me
- I want to print a message in post ” After one month from publish date”
- How to query details of images in gallery that is attached to a post
- Custom API plugin to execute 3rd party API to retrieve data
- WordPress Child Theme Stylesheet being loaded before Parent’s minified .css
- How to create custom search page
- Where to store reusable content that is not a page
- WordPress broken after changing URL
- How to have multiple WordPress Menus
- How to make the Pages in WordPress Customized?
- Custom “wp_login.php?action=lostpassword” and reset password
- Where to upload my new custom ShortCode in Separate .php file?
- wp_enqueue_script JS code runs too late (after user begins interacting)
- Get custom text if in Category
- Conditional Logic on CF7 dropdown options
- Change admin_title of a plugin using code snippet/functions
- Validate user login in php
- REST public POST giving 403 forbidden nginx
- Adding a custom field to a slug
- Query Product categories what have a custom field
- How to create custom backend admin menu in different languages?
- 404 error custom post type rest api
- WordPress Performance and bulk edits
- Delete page titles
- Woocommerce dependent attributes
- WordPress Customizer: Check for value of CSS selector and replace it
- Jquery wrap permalink in a data-attribute?
- How to add custom Author Info Box to blog posts “only” and NOT custom post templates
- Bio comes up when the visitor clicks on a picture
- How to find and replace (or add) specific word in a specific category?
- Creating a Treeview Listing of a Directory
- WooCommerce – Adding custom HTML to specific product pages
- How do I move my sites to a child theme without loosing customisation?
- Displaying all Custom fields on post except some
- How to create new page can get custom field other post in wordpress
- How to appoint different users to different pages?
- insert autofocus in a custom taxonomy form
- Is there a way to hide a user’s posts from their Activity feed?
- customize footer widgets area
- Accessing + retrieving custom database in WordPress
- updated permalink structure on localhost does not work
- Word Press Theme Customiser and Child theme Function.php
- Security Issues with custom user role or changing core role capabilities?
- adding new html css to wordpress section from codepen [closed]
- Disable all Fonts that are Standard in WordPress and replacing them with a custom Font?
- Custom product sorting archive page
- Add custom information in editor summary
- A Voting system for a pageants