Use the_content
hook and hook only when you are on a single page:
add_filter( 'the_content', 'my_button_function' );
function my_button_function( $content ) {
// See if it's a single post or a loop
if ( is_single() && in_the_loop() && is_main_query() ) {
return $content . "<button onclick=\"buttonAction()\" p style=\"font-size:10px\" id=\"ActionButton\">ACTION</button>";
}
return $content;
}
This will only add the button if you are on a single post, and will add the button at the end of your content.
Further reading at : WordPress Developer’s website.
Related Posts:
- Handling error states with admin_post
- get_the_content if it contains multiple lines it results in SyntaxError
- Looking to exclude blog posts from category Previous/Next buttons
- Insert code when users come from an specific referer
- Automatic Excerpt Not Working
- How to display related posts from parent category
- Using a javascript file to access a get posts array
- Make custom field meta not display if there is not data in it
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- Get_the_author doesn’t return author name
- Trying to make php run in a post
- Remove posts after a given amount of time
- Hide wordpress field if data is empty in post!
- Button not refreshing page
- Trying to add attribute to my posts’ featured image
- How to make a search button that will search my website?
- How to show part of the_content?
- How to set a min number of words for a blog post
- Get post id in a function when edit/add a post
- Post + form + action + results on the same page
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Post repeating with infinite scroll
- Count posts on multisite with blog id
- Making (and edit existing) posts with ID included
- Parsing Menu Items and Blog Posts
- Pagination on Custom Post
- $wpdb returns duplicate posts
- How to avoid duplicates when creating recent network posts
- How to show an entire post content and not also the excerpt?
- Update post title from external file?
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Increment paged on WP_Query
- How to use mysql LIKE with wpdb?
- Do I need to edit my theme in order to change the title of my blog page?
- Add new post in existing categories using wp_insert_post
- How do I add more options to the post-new.php page?
- Modify main query before it run without pre_get_post
- .html end of URl affected to SEO?
- Get the id of all images in a post
- Do not duplicate posts with multiple categories in multiple loops
- Four posts per row [closed]
- Update if post with specific title exists
- Need help removing […] after excerpt
- WordPress Search
- Update value of a associative array with update_post_meta
- Pagination in single.php
- Edit and delete permissions pages and posts
- Advanced Query posts
- Add a product category to a specific product via a button
- My Custom Post Type AJAX Query is Returning no posts – why?
- Post form – AJAX won’t upload featured image – Plugin development
- How to get post image caption by index
- posts_per_page displays only 2 posts instead of 4 posts
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- Is there anyway I can call the year once?
- Change button link to add nonce
- Check $post->ID against multiple values
- Don’t update modified post date when user add a product review or comment?
- Limit the number of characters/words in an excerpt for a related posts section
- Posts missing on author page
- How to allow users to save list of posts in wordpress?
- Need to show 7 posts from actual date
- Can I disable auto increment of WordPress Posts Database to utilize previously deleted records?
- How to edit button permalink inside function.php using a child theme?
- Closing Comments conditionally in comments.php
- How to center all text body in single.php at once?
- Having trouble with customizing blog posts on the home page
- How do I stop my form from adding code to current page URL instead of re-directing. Been stuck for days
- Related Posts: if there is no category use tags
- LinkedIn Share Post Button
- How do if all posts has this category ID then do this
- Get the total Author Favorited posts
- Get current_post in reverse order with pagination
- Getting error in sql query
- How do I generate formatted permalinks as specified in backend options?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Insert div after every three posts in home.php [duplicate]
- PHP tag in post content makes wordpress go crazy
- Unable to get Post Category Name and URL
- Dynamically Create Posts Via XML File
- Basic PHP question (displaying post title over thumbnail) [closed]
- insert thumbnail image from php script
- Post from front end form to post_meta
- media_handle_sideload() returned post_id being incremented
- Saving Post redirects to 404 page when php $_GET variable in post body
- Functions are causing errors
- Insert wordpress tags below posts via functions.php
- How can I add WordPress Audio Player as featured audio in Audio Blog Posts?
- Trying to see if page is category or single and displaying title with appropriate heading tag
- link to page_for_posts
- How to customize posts in WordPress by using HTML and CSS?
- foreach all the post
- How to create a loop that will display one post and stop?
- Blog Posts not sorted and pagination not adjusted after filtering some category
- Add multiple HTML attributes to an Elementor button
- How to create a WordPress PAGE in another folder?
- How do I get a function to work in single.php
- Count the number of matching post names in foreach loop
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)