How to Automatically Insert Content After Each WordPress Post?

WordPress is easier to use and it is a versatile blogging platform and here we can customize and develop different themes and plugins and it works in a dual manner. For layman one could use different customized plugins and add-ons and for the geeks there is already the room for adding extra codes and then without using the add ins and plugins one could make WordPress behave that way.

The functions.php file of the theme works in various ways and one can provide enough customizations and additions to it so that many different and some critical functions can work in seamless ways. It is a must that one should do from cPanel while doing editing of any of theme files.

Some people use from WordPress front end that is WordPress admin and in this process, they reach to the stage where with some sort of wrongdoing entire website could be in jeopardy and become down from the internet.

If you want to place some permanent information after each post, then you can do it with some custom codes pasted into functions.php files and that information surely will be visible at the end of each and every article.

How to insert custom content after each post?

When you go through any of WordPress posts you could find apart from the changing nature of the articles which is different in each single post there are many common attributes are the inside single post and most of these are done through this following WordPress snippets through its functions.php files.

Through functions.php file we could help and manage the static contents to be showed inside WordPress single content. Here are the code snippets to be pasted at the end of functions.php file.

 
 // add custom post content
 function add_post_content($content) {
 if(!is_feed() && !is_home()) {
 $content .= '<p>This article is copyright &copy; '.date('Y').'&nbsp;'.bloginfo('name').'</p>';
 }
 return $content;
 }
 add_filter('the_content', 'add_post_content');

What this code snippet will make is that it will show the copyright information at the end of the article and if you have modified version of related posts code with css then perhaps you will have to further modify this code otherwise this works seamlessly.

In my template there is the related posts code and for this the visibility of this function code is broken and that is why I am still trying to find out the other way out but if you have some other theme then it can work fine.

The next code snippet is about how to enable and easily display the total number of post’s word count. This actually works nicely if you write lengthier article and you want to display to the readers that you have written some 1000 worded or more article. There is a code snippet to do this and let us do it now.

There is the caution while doing these code snippets is that you should do it at your own risk and if you are not confident enough, then it is better not to do it and if you do it, then make it the backup of the edited file of the theme so that when at any point of time anything worse happens then you can easily upload the previous best option to make your site live again.

How to count words in posts?

As always I advise you to do this from File Explorer through the panel and before editing any of theme files first download the copy to your local computer and then do the editing online. In this function, we will be learning about how to display the count of yours post’s word count and for this first open the functions.php file of yours currently activate theme.

Go to the extreme end of functions.php file and then paste the following code snippet and save the file.

// count words in posts
 function word_count() {
 global $post;
 echo str_word_count($post->post_content);
 }

This is the first stage of the code snippet where the first code is pasted into functions.php and then in the next stage we will be moving into the stage where we would like the total count of words of posts to be displayed and for this we would like to paste it somewhere so that it would be visible.

The posted code is as follows:

<p>This post contains a whopping <?php word_count(); ?> words.</p>

Now, let us do some customization:

I always fond of Twenty Twelve theme and I you are using it then you would be using its child theme and then open the content.php of it and then move to the following line of the content.php file.

 
<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>

As always before doing anything back up the file to local computer so that at any point of time yours code editing goes wrong and your site down then just replace the backup copy with it.
Place the following code just after it.

<?php if ( is_singular() ) : ?>
 <p>This post contains a whopping <?php word_count(); ?> words.</p>

<?php endif; ?>

Save the content.php file and then open single post file and then scroll down to the end of the article and before author link and you will find that there will be written as ‘This post contains a whopping ….. words’. In the place of dots, you will find the number of words that are used in the article.

The code is as follows. The code

 
 <?php if ( is_singular() ) : ?>

<?php endif; ?>

Says that this information should be visible to single posts instead of the front page or index pages and this means that when you browse the article inside you could see the information there.

This information puts in between those two lines will only be visible when you browse the website o single post pages and this means that the attached information will only be visible when you enter into the length of article and by using this code and placing anything such as advertisements to show it only at the single pages and this means that you can then allow your visitors to see specific ads when they enter into that page only.

What we learn from this article is that there are endless possibilities to use your WordPress site and knowledge and the way you manage your expertise and the way you intended to go over it and from time to time you would see that only smaller form of code snippets that make each and every form of WordPress site most beautiful and there is, of course, no need for further add-ons and plugins to make your site more exhausted with it.

There are endless possibilities like that at the end of this article we are able to show codes in single posts only with a little bit of code and subsequently we do find plenty of other avenues such as showing the date and the latest updated formats and so on and there is the vast depository of article in Google search and you can find it and then try to implement with your themes and if all goes in a good way then all these be at the end of it works nicely and that will make you feel as a developer.

Code Source: https[:][//]digwp[.]com[/]2010][/04][/][[wordpress-custom-functions-php-template-part-2][/]


Related Posts:

  1. Inserts media.net or Adsense advertisement code after a few paragraphs
  2. How to show breadcrumbs without a plugin for Twenty Twelve Theme in WordPress
  3. How to Add Google Analytics to WordPress Without a Plugin?
  4. How to Add Pagination to TwentyTwelve Theme of Your WordPress Blog without a Plugin
  5. How to add copyright in footer of wordpress without plugins?
  6. Creating Child Theme from an unmodified Parent Theme
  7. Create a Landing Page Without Code Or Plugins

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.