• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Ani's Webdev Blog

A learning diary of website development

  • Home
  • Demo
    • Ajax Contact Form
  • WordPress
  • Front-end
  • Backend

[WordPress] Add content at the end of every post without plugins

Modified on: September 19, 2020

Sometimes you may want to add information to every posts but don’t want to open every single post to add that line.

In this article, I will show you how to implement three use cases simply by using wordpress add_filter and the_content hook. You may add anything at the end, or at the beginning, of each post:

  • Case 1: Add a simple line of text
  • Case 2: Add a button of PayPal donate

Table of contents

  1. Add a simple line of text at the end of every post
    1. Add a PayPal donate button at the end of every post
      1. Limit the content to show in only some pages

        Add a simple line of text at the end of every post

        Go to functions.php in your theme folder and add in the code:

        PHP

        And then go to check your posts. You will see this line has been added to the end.

        Similarly, you can add line at the beginning of each post, just change this line:

        PHP

        into this:

        PHP

        Add a PayPal donate button at the end of every post

        First, a donate button in PayPal need to be setup.

        Follow the instructions here to register a donate PayPal button and finally you will have a code snippet or an URL to be embedded anywhere. In this case, I will use the shareable URL.

        Creating a donate button in PayPal and getting shareable URL
        Creating a donate button in PayPal and getting shareable URL

        Then, using the same the_content hook and add_filter, add the button at the end (or beginning) of every post:

        Go to functions.php in your theme folder and add:

        PHP

        Let’s style the button a bit.

        CSS

        As a demo, please look at the end of this post.

        Limit the content to show in only some pages

        Sometimes you might want to show different messages based on the page where users are. Simply add a condition to the function in functions.php using WordPress’s built in such as is_page(), is_single(), is_singular() or is_front_page().

        For example, I limit the donate button to only show in this post.

        PHP

        Filed Under: Wordpress, WordPress Themes Tagged With: add_filter, php, wordpress hooks

        Recent posts

        [WordPress] Let’s Make Plugin E01: A Simple View Count Plugin

        [WordPress] Create custom post type programmatically

        [WordPress] Open Images in Posts into Lightboxes On Clicks (Without Plugins)

        Reader Interactions

        You are here: Home / Wordpress / [WordPress] Add content at the end of every post without plugins

        Leave a Reply Cancel reply

        Your email address will not be published. Required fields are marked *

        Primary Sidebar

        Hi! I am a Vietnamese coder living in Oulu, Finland. Currently I am working with PHP, MySQL, HTML, CSS, and JavaScript. This blog is my learning diary, in which I share knowledge from my own experience or research. Hopefully you can find something useful here and don’t hesitate to open a discussion or leave a feedback!

        FOLLOW MY BLOG

        Thank you for visiting this website! I hope you find something useful here :). Contact me by email: anh@anhkarppinen.com.