How To Remove Image & wp caption text from the_content in Frontpage WordPress

We have and image with wp-caption that we put on the first/second paragraph before <!--more--> and we didn’t want this image displayed on the Frontpage and display on Details or Single Page.

Why we need it? Because on the Frontpage we already use Feature Image,  so.. how to do that?

We will show you how to do that, we need do extra step by put some function on Current Active theme functions.php and using WordPress add_filter features. Check it out and we will show you how to do that.

Another Tutorial: Put Google Rich Snippet Friendly Breadcrumb on WordPress

To make it work, we use regex to manipulate the_content() data. Regex (Regular Expression) is unique ways to manipulate string. Here is what Wikipedia said about Regular Expression

Baca Juga  5 Tips dan Cara Untuk Tidur bagi Orang yang Susah Tidur
Remove image and wp-caption WordPress
Remove image and wp-caption WordPress

A regular expression, regex or regexp (sometimes called a rational expression) is, in theoretical computer science and formal language theory, a sequence of characters that define a search pattern. Usually this pattern is then used by string searching algorithms for “find” or “find and replace” operations on strings. (wiki)

Regex Concept founded by Stephen Cole Kleene

He we go, remove image and wp caption on Post Content WordPress Frontpage and Archive Page

  1. There are many method, you can using WordPress Editor, or you can use FTP service and edit functions.php file via FTP Editor.
  2. Goes to functions.php on your current theme and edit it.
  3. After that files opened, just copy and paste this code in the end of your functions.php
  4. On The Code above, the code will strip all content in wp caption (included image) and didn’t display on NON SINGLE page.
  5. Save your work
Baca Juga  Cara Mudah Praktis dan Cepat Mengatasi Performa Windows 10 yang Lemot biar Gesit Lagi

Now, on the Frontpage the_content(); all wp-caption and images will be remove and the_content(); will display Text only.

You can enhanced that code, example hide on the frontpage but display on the archive, display on the search and many more. Just play around with code above.

We also put same regex to hide image but wp-caption text will be displayed. Just uncomment 1 regex and comment on current regex.

Baca Juga  How To Move WordPress Admin Bar to the Bottom Area


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.