How can I customize the_content(); output? [closed]

You can add a filter to the content directly on functions.php and use str_replace or perhaps some preg_replace (regex) to change the output of the content. Not tested. Try something like this: function add_class_to_img_and_p_in_content($content) { $pattern =”/<img(.*?)class=\”(.*?)\”(.*?)>/i”; $replacement=”<img$1class=”$2 newclass newclasstwo”$3>”; $content = preg_replace($pattern, $replacement, $content); $pattern =”/<p(.*?)class=\”(.*?)\”(.*?)>/i”; $replacement=”<p$1class=”$2 newclass newclasstwo”$3>”; $content = preg_replace($pattern, $replacement, $content); … Read more

Create a shortcode to display the “the_content ()” in my post [closed]

Here is an example of a shortcode that renders post content based on the id and type attribute. [post type=”content” id=”2″] [post type=”title” id=”2″] If you want to render from a template you would use: echo do_shortcode ( ‘[post type=”content” id=”294″]’ ); echo do_shortcode ( ‘[post type=”title” id=”294″]’ ); And here is the actual shortcode … Read more

Creating mixture of shortcodes to use in the visual/text editor

I suggest to just append the other things to the content without editing the templates add_filter(‘the_content’,’hang_my_specific_things_on_the_content’); function hang_my_specific_things_on_the_content($content) { // shortcode0 is appended before content $content = do_shortcode(‘[shortcode0]’).$content; // these are appended after the content $content .= do_shortcode(‘[shortcode1]’); $content .= ‘<img src=”https://wordpress.stackexchange.com/questions/312880/someimage.png” />’; $content .= do_shortcode(‘[shortcode2]’); return $content; }

Adding schema to text content in the loop, how?

Just add them to echo <?php if ( has_post_thumbnail() ) { the_post_thumbnail( ‘full’, array( ‘class’=>’post_thumbnail_common’, ‘alt’ => get_the_title() , ‘title’ => get_the_title(), ‘itemprop’=>’image’ ) ); echo ‘<div itemscope itemtype=”http://schema.org/BlogPosting”>’.contentnoimg(41).'</div>’; } else { echo content(41); } ?>

How to remove only images from the_content() [duplicate]

This answer already here How to remove images from showing in a post with the_content()? <?php $content = get_the_content(); $content = preg_replace(“/<img[^>]+\>/i”, ” “, $content); $content = apply_filters(‘the_content’, $content); $content = str_replace(‘]]>’, ‘]]>’, $content); echo $content; ?>

How add class the_content();?

You don’t. You’ll need to put an element around it: <?php if ( $content_source == ‘excerpt’ ) { ?> <div class=”excerpt”> <?php the_excerpt(); ?> </div> <?php } else { ?> <div class=”content”> <?php the_content(); ?> </div> <?php } ?>

Find and replace weird characters in the_content [closed]

You could try this: <?php function replace_content($content) { $search = array(‘&’, ‘é’, ‘—’, ‘‘’, ‘’’, ‘“’, ‘”’); $replace = array(‘&’, ‘é’, ‘—’, ‘‘’, ‘’’, ‘“’, ‘”’); $content = str_replace($search, $replace, $content); return $content; } ?> Credit to Harry on WordPress forums

the_content() “crashes” for single pages

the_content( ); vs get_the_content(); The different is pretty simple actually. If you find yourself annoyed with formatting of the content, more specifically the added p-tags that WordPress puts into the content that you didn’t. Just use get_the_content(); and you will remove those tags. Normally the get_the_content() tag returns the content WITHOUT formatting. Only the_content() will … Read more

Excerpt all post content Content Same Size without word cutting off

I use wp_trim_words to create multiple excerpts. I always abuse it when I need more than one excerpt length. Here is how function wpse_custom_excerpts($limit) { return wp_trim_words(get_the_excerpt(), $limit, ‘<a href=”‘. esc_url( get_permalink() ) . ‘”>’ . ‘&nbsp;&hellip;’ . __( ‘Read more &nbsp;&raquo;’, ‘wpse’ ) . ‘</a>’); } What this function do is taking get_the_excerpt trimming … Read more