There are hooks that you can use for this purpose.
The wp_head hook allows you to add your content to the header, while wp_footer does the same for your footer.
Use it as follows:
add_action( 'wp_head', 'my_function');
function my_function (){
echo "Hello World!";
}
This will print Hello World! in your header.
However, there is an important note. The theme must have wp_head(); and wp_footer(); in its template files. Almost every theme has these files, so you can safely use this in most cases.
To print anything in a template from a plugin, you have to actually hook to some action or filter. If there is none of these in that template file, then you simply can’t echo your content there, and must find somewhere else to do so.
Related Posts:
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- Upgrade 4.5.2 to 4.5.3 deleting row in wp_options table
- Between functions.php (theme), widgets, and plugins, which is loaded first?
- Beta Versioning of Plugins
- How can I make default jquery version of WordPress “async”?
- How to add plugins to wordpress theme?
- WooCommerce – Show shipping cost on product page [closed]
- Importing Tweets with certain hashtags into WordPress
- Get php var inside javascript file (making plugin)
- Find out what is using PHP sessions in WordPress
- Using Vagrant for customizable WordPress Multi-sites [closed]
- Override dynamic_sidebar() in plugin?
- How to update WordPress plugin readme.txt description page without triggering a plugin update?
- publish_post hook isn’t working for scheduled posts
- Creating a theme option page?
- Add post thumbnail from external image with plugin
- Why is this custom taxonomy showing in the database?
- Where is the source code that makes the “all” array grabs filters in the $wp_filter?
- How can I change plugin to give access to editor user role?
- Is it possible to add an action to the currently running action?
- How do I get slug of all active plugins programmatically?
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- unzip a folder on specific location and delete the zip file
- Check if User exists in WordPress Multisite
- WordPress author details plugin/widget
- Embed a Google Sheet as you view it in a separate tab?
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- WordPress download manager plugin showing attached file is missing/deleted?
- Different UI in WordPress
- How to add links in .po (language) file in wordpress?
- Display update notification messages like ‘What’s New’
- Does any one have Idea to get these functionalities with the plugin wp-multi-network
- Gutenberg block can’t save richtext
- How can I make 2 plugins that include different versions of a framework to both use the latest version?
- Add Plugin options as subpage to Theme options page
- Image upload and download from front-end
- correct way to include a library(and its dependent libraries) in wordpress development
- Issue Tracker from pre exsisting table [closed]
- Changing page URL and connect newsletter to MailChip
- Git Hosting for WordPress SVN Plugin Repository [closed]
- How to enable AMP for custom single template with custom database
- Problem with the Loop – want to limit the access to three free articles
- How to exclude certain files from the plugin editor?
- WordPress and a secondary database?
- Custom table naming/access convention for multisite: $table_prefix vs base_prefix or other?
- Problems With WP Bannarize Plugin [closed]
- How to create a child/addon plugin
- How to secure the release of WordPress plugins / avoid copying plugins?
- What happens if I don’t update my plugins?
- how to force tag page layout to use same as search layout?
- Gutenberg Block Style CSS Class Is Not Applying on Backend
- WordPress Users authentication with Java Application
- remove_action not removing add_action from constructor
- Replacing global wp_query
- Is there a way to make the main page only display a brief description of the full article?
- how to make wordpress plugin from PersianWebToolkit? [closed]
- Limit WP code scope into plugin
- Custom search search does not work?
- WordPress custom plugin that uses woocommerce enabled payment gateway for payment [closed]
- Execute a function when the entire page is displayed
- Add custom PHP and HTML to the_content()
- Cannot read properties of undefined (reading ‘firstChild’) using photoswipe in product page
- Find Plugin by file name
- Creating an admin button that when clicked shows a popup form
- Add an action based on custom post meta field
- How to hide an option from dropdown in filter module
- Downloading a file
- $wpdb not working wordpress plugin ajax call
- how to create user profile pages and display them based on users roles
- How to change “Read More” text?
- How to use wp_editor and save its data in wp_posts table
- WordPress database problem wp_posts, primary key
- Auto trigger of popup
- Woocommerce – Change variations output
- WordPress Plugin PHP Not Calling Function
- how do i fixe Page Builder on a custom page?
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Do_shortcode before send email content
- wp_enqueue_scrpts seems not to get called
- Adding featured image to post display widget
- How to Create Custom Dashboard for my Laundry Website?
- Warning: Illegal offset type in /var/www/html/wp-includes/option.php on line 1924
- Get plugin to background of page
- How to create a WordPress sandbox on a live server for website development?
- What is a good way to test that plugin upgrades have completed properly?
- get post excerpt by query
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- Deleted plugins displays error message
- Remove the ‘Press This’ Tool
- __FILE__ in WordPress plugins
- Looking for a related post plugin which slides-in like the one at inc.com does [closed]
- which is this plugin ? [closed]
- cmb2 select option output [closed]
- Woocommerce Product Add-ons – Auto-select first option
- Sync roles across several plugins
- How to write a specific url for only single page in wordpress?
- Jquery post responses 500 error after some time and lastly an 503 error
- Identifying Plugins Based on Tables [closed]
- Can’t save formdata in DB
- How to apply an additional fee for the layaway payment