Home > php > Display only text to WordPress loop without loosing the text formatting

Display only text to WordPress loop without loosing the text formatting

December 18Hits:52
Advertisement

I want to display text from content (only text) with the formating (paragraph, bold, italic.) on loop. When I am using this code:

<?php echo mb_substr( strip_tags( get_the_excerpt() ),0,255); ?> 

or

<?php the_excerpt(); ?> 

The text displayed without the text formating. No p, br even the hr is disappear.

When I am using this code:

<?php echo apply_filters('the_content',substr(get_the_content(),0,550)); ?> 

The text displayed with the format, but the other content also display (image, video and else) I just want to display the text with the format.

Anybody know how to resolve the problem? Really appreciate for any help

Thank you

Answers

Try this code in your theme's functions.php file-

function filtered_content($content){
    $content = preg_replace("/<img[^>]+\>/i", "", $content); // removes images
    $content = preg_replace('/<iframe.*?>/', "", $content); // removes iframes
    return $content;
}
add_filter('the_content', 'filtered_content');

This will remove img and iframe tag from your content. Then use the_content() in your template.

Tags:php, text, filters, loop

Related Articles

  • Display only text to WordPress loop without loosing the text formattingDecember 18

    I want to display text from content (only text) with the formating (paragraph, bold, italic.) on loop. When I am using this code: <?php echo mb_substr( strip_tags( get_the_excerpt() ),0,255); ?> or <?php the_excerpt(); ?> The text displayed wi

  • Display text from post on WordPress loop without loosing the text formattingNovember 10

    I want to display text from content (only text) with the formating (paragraph, bold, italic.) on loop. When I am using this code: <?php echo mb_substr( strip_tags( get_the_excerpt() ),0,255); ?> or <?php the_excerpt(); ?> The text displayed wi

  • How to toggle a div element between two images when click two submit buttons in a wordpress loop?December 13

    How to toggle a div element between two images in a wordpress loop when click two submit buttons simultaneously? I have one div, 1st image should select when i click on the first submit button and then 2nd image while click 2nd button. Now this is co

  • Wordpress loop with nested bootstrap tabsOctober 19

    I have been trying to get this to work for a couple of days, but I am stuck. I am generating the initial tabs using a wordpress loop. Each tab is a post. I have information within each post that I want to display in tabs withing the post tabs. I can

  • Wordpress Loop - Style rows of posts differentlySeptember 27

    I am trying to adapt the Wordpress loop to style posts differently in rows that get infinitely smaller until all posts are displayed The concept here is to display posts in rows first row 1 post second row 2 posts third row 3 posts fourth row 4 posts

  • Wordpress "Loop" with large set of resultsJanuary 22

    I'm not sure the appropriate terminology but I have a wordpress "loop" for a custom post type that has roughly 300 results that all get displayed on a single page (no paging). The causes an enormous load on the DB server because for every "

  • Dynamically name array in Wordpress loop - add/get valuesJuly 9

    I have a page set up like Page One, Page Two, Page Three Each page has a tag of 'content'. In the Wordpress loop I would like to create an array for each page with the page title as the array name. I would then like to add and get values from the arr

  • 'Auto Draft' Post showing in wordpress loop

    'Auto Draft' Post showing in wordpress loopJanuary 21

    When running a wordpress loop, I am seeing these weird posts called auto draft. I have never seen this before. Does anyone know what they are and how to get rid of them? Any help is appreciated as I am lost on this one. THe loop I used is: <div class

  • Custom fields are not displaying in page with multiple loops

    Custom fields are not displaying in page with multiple loopsJanuary 27

    I have multiple loops on my home page. I am trying to display custom fields in each loop. But some of them are not showing. Any idea, why? Here is the code: //check for Featured Events here $featured = new WP_Query (array( 'category_name' => 'Feature

  • WordPress loop to pull 4 pages/posts by IDMarch 11

    Im trying to create a wordpress loop which pulls out 4 specific pages/posts by ID (excepts to display a teaser). The main issue is they are located in 3 different post types: 'post', 'training', 'page'. So far I have rewrote this code 3 times, its ne

  • Edit Wordpress loop, taxonomies, & filterMay 1

    I have managed to integrate a custom taxonomies plugin that: -Filters down the staff depending on what category is selected. I want it to show that department first, and then the other departments beneath rather than that department all on its own (h

  • what is the maximum number of post a wordpress loop can work with?June 18

    what is the maximum number of post a wordpress loop can work with? how many post can i display with 'posts_per_page' => -1? ive got 50,000+ pages and I want to sort through them, but I just get a blank page whenever I try and do anything to more than

  • Getting Bootstrap accordion working in Wordpress loop with custom post type (collapsing issue)

    Getting Bootstrap accordion working in Wordpress loop with custom post type (collapsing issue)November 14

    First off I am well aware that there is a plugin but I am NOT talking about the BS Short code plugin. I am talking about the actual bootstrap accordion. So here is what I am trying to accomplish, I am pretty close I am trying to use custom post types

  • How to bring specific post to front of wordpress loop?January 10

    So, I have a WordPress loop going on. The below code is the template page for the woocommerce product archive page. Here's the use case for what I am trying to find out how to achieve: User is displayed with product archive page (product thumbnails w

  • Adding some sort of Label-text to a looped button

    Adding some sort of Label-text to a looped buttonJune 10

    To sum up my problem, here's a picture: I've added this text with a hover-fx to a button to explain to users what the button does. I've done so by adding a <div> with another <a>-element in it and coding the necessary stuff via CSS. However th

  • Get custom field outside wordpress loop on new php pageNovember 13

    I want to get a specific custom field value to display outside the wordpress loop in a new php page. right now im using the code below, which is doing what i want but in a ugly way. i need to exclude all custom fields except the one i want to get. in

  • disable wp-pagenavi on pages with template using the wordpress loopJanuary 1

    How can i disable wp-pagenavi on pages using templates and the wordpress loop? It seems that wp-pagenavi adds itself automatically wherever the wordpress loop is used, not counting that it is a page or not. --------------Solutions------------- you pr

  • Modify main WordPress loop with a parse_query filterMarch 29

    I am trying to modify the main WordPress loop on my category pages like so: add_filter('parse_query', 'my_modified_query'); function my_modified_query( $q ) { if (!is_admin() && is_category()) { $q->set( 'orderby', 'meta_value' ); $q->set( '

  • Wordpress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next pageApril 30

    Hey everyone. I'm not sure if what I'm experiencing is a result of a bug (due to the recent upgrade to 3.1.2) or poor coding. Ever since i upgraded to version 3.1.2 ive been experiencing a problem with two loops on my index page. Here's what I've got

  • Wordpress loop not working on blog.php pageJuly 14

    Well, i'm creating a wordpress theme, but i can't get wordpress loop to work correctly for some reason. This code works fine in index.php : <?php if (have_posts()) : while (have_posts()) : the_post(); var_dump($post); endwhile; endif; ?> But, it doe

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.832 s.