Filters should return, not echo.
function my_content( $content ) {
// Something something
$content="my content";
return $content;
}
add_filter( 'the_content', 'my_content' );
You can echo, but you’ll need output buffering, like this:
function my_content( $content ) {
// Something something
ob_start();
echo 'my content';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_filter( 'the_content', 'my_content' );
Also, the reason you’re seeing your output in the head section is because the filter is likely being used somewhere in the head section, perhaps by some plugin, so be careful since you might be overriding something more than you’re hoping to.
Hope that helps.
Related Posts:
- Get page content using slug
- Change the_title() of a page dynamically
- the_content after all shortcodes are parsed
- How to edit the properties of a page programmatically?
- Is it possible to remove next-post / previous-post with out creating a custom template?
- How to ensure “the_content” filter runs only for the main displayed content?
- Filter to change the content of 404 page
- Pages 404 in wordpress
- How to create a dynamic page based on form data with a plugin?
- Use an empty page to build custom plugin output
- Is it possible for a plugin to register a page template file?
- Dropdown list of pages to get page id to store in plugin options
- Calling a function from functions.php in custom page/ blog post
- How do I approach removing menu items on the fly based on settings in my plugin?
- Set a specific page as 404 – not found via my own plugin
- Create a Page via plugin
- Finding the paragraphs in content
- $content variable – Is this a reserved variable for a WordPress function? – php / wordpress
- Secure Pages Best Practice
- How to filter the_content() & include content from template
- Caching the_content calls
- Run Shortcode of post’s custom field in functions.php / Plugin
- Plugin generated virtual pages
- Proper way to replace the_content only for pages created by custom plugin
- What happens when two or more plugins use the same hook?
- Add Password Generator on password protected page
- WordPress pages are not published due to External database connection with WPDB class
- Inserted double quote when prepending to the_content
- Create page (not the post type) dynamically
- Add function after the_content
- Multiple array for post_content on plugin activation
- Shortcode conflicts
- How to list all images used on a specific page?
- Create fixed static pages
- Information on plugin adding text when a post, page, or other such is displayed
- Can / should a widget plugin define its own Widget Area?
- Set page to draft on plugin deactivation
- How to create archive page to add in menu
- Load specific page when a custom URL is hit
- Is there a way to get rendered html content of a WP post after updating?
- Plugin frontend page design irrespective of the theme used
- Custom non-template page on front end fails to render
- Custom signature appears twice on page
- How do I control the list of Pages an author can see?
- Filter the_content() to add custom figure tags
- How to add conent (text) to Add New pages form of admin in WordPress
- auto create only 1 wp page in activate custom plugin
- Create pages for authors
- How to parse without changing the characters case (lower and upper) in wordpress the_content?
- append code after the_content not working
- add_filter adds output in the head
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- echo statement repeats
- Using a Page Template Not in Theme
- Generating Multiple Divi Pages from Database
- Problem with Owl Carousel, infinite loop [closed]
- Is there a way to decide from init whether we are on a certain backend page?
- Can a WordPress plugin add read-only pages?
- Objective Best Practices for Plugin Development? [closed]
- add_menu_page() with different name for first submenu item
- Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
- How to include PHP files in plugins the correct way
- How can I add an image upload field directly to a custom write panel?
- A tool to analyze rewrite rules? [closed]
- Difference Between Filter and Action Hooks?
- framework for plugin/theme options panel? [closed]
- Creating a table in the admin-style?
- How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
- Settings API with arrays example
- How to get the path to the current theme?
- How to make a plugin require another plugin?
- ajaxurl not defined on front end
- What process do you use for WordPress development? [closed]
- What’s the difference between term_id and term_taxonomy_id
- Should I use wpdb prepare?
- Why does WordPress use outdated jQuery v1.12.4?
- Post meta vs separate database tables
- Is there any plugin development framework
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- How to add a javascript snippet to the footer that requires jQuery
- Enhance Media Manager for Gallery
- How do I create a custom role capability?
- How do I add CSS options to my plugin without using inline styles?
- How do i best handle custom plugin page actions?
- Adding Custom Text Patterns in the WP 4.5 Visual Editor
- Automatically determine minimum WordPress version required for a plugin?
- What is the advantage of using wp_mail?
- How to make a WordPress plugin translation ready?
- How many times will this code run? (or, how rich is grandma?)
- How to create an API for my plugin?
- Is it ever okay to include inline CSS in plugins?
- Plugins in symlinked directories?
- How to override existing plugin action with new action
- How to include a file using get_template_part() in a plugin?
- Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
- How to store username and password to API in wordpress option DB?
- body_class hook for admin pages
- “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
- Is it mandatory to use $wpdb->prefix in custom tables
- Which hook should be used to add an action containing a redirect?