post_content with line breaks

I believe this should work: $getPost = get_the_content(); $postwithbreaks = wpautop( $getPost, true/false ); echo $postwithbreaks; The second argument in wpautop can be up to you whether it’s true of false, see the link below. It is described as follows: (bool) (Optional) If set, this will convert all remaining line breaks after paragraphing. Line breaks … Read more

Only show content before more tag

You can use the WordPress function get_extended to fetch the different parts of a string (the part before and the part after the <!–more–> tag). get_extended returns an array with three keys, of which the keys main and extended are important: $arr[‘main’] contains the part before the more tag, and $arr[‘extended’] the part after the … Read more

the_content and is_main_query

To be honest, the function in_the_loop() is what you are looking for: add_filter( ‘the_content’, ‘custom_content’ ); function custom_content( $content ) { if ( in_the_loop() ) { // My custom content that I add to the_content() } return $content; } What in_the_loop does is to check if global for $wp_query (that is the main query object) … Read more

Split Content and Gallery

Open to anybody who can simplify this but here’s what I came up with that worked for me. First thing’s first – get the gallery, using get_post_gallery(), as soon as the loop starts: <?php if( have_posts() ) : ?> <?php while( have_posts() ) : the_post(); $gallery = get_post_gallery(); $content = strip_shortcode_gallery( get_the_content() ); ?> <div … Read more