Why is overwriting $GLOBALS killing the_content()?

Template tags like the_content() and the_title() are dependent on the global $post variable ($GLOBALS[‘post’]). See the source code for get_post(), which get_the_title(), for example, uses to get the current post so it can get its title: function get_post( $post = null, $output = OBJECT, $filter=”raw” ) { if ( empty( $post ) && isset( $GLOBALS[‘post’] … Read more

Use content from one page in another template

Assuming you have the following pages: Home About us that has a slug of about-us And you want to display the content of the About us page into the Home page. <?php $about_us = get_page_by_path(‘about-us’); // supply the page slug; i.e. about-us $about_us_content = get_the_content($about_us->ID); ?> <div><?php echo $about_us_content ; ?></div> Alternatively, you can use … Read more

How to split a post and intercalate elements from a loop

You can buffer the template part to use it within post content: <?php add_filter( ‘the_content’, ‘add_related_each_nth_p’ ); function add_related_each_nth_p( $content ) { if ( ! is_single() ) { return $content; } // the interval between added content $paragraph_steps = 3; // declare empty output $output=””; // declare related posts offset $z = 0; // make … Read more

Get the_content surrounded by instead of

First you should use get_the_content() to assign the content to a variable (instead of the_content() which is meant to display it instead of returning it). Then you will want to apply filters hooked to ‘the_content’ just like the_content() does (see the source). Here is a revised version of your original code: $thisPagesContent = get_the_content(); $thisPagesContent … Read more

Split the_content into two parts

Solution one: As the wise commenter mentioned, you can use excerpts. the_excerpt() (link) “retrieves the post excerpt”. get_the_excerpt() is going to be a string so you can wrap it up in whatever you fancy and after that, you can call the_content() to get the rest. The only downside that I see is that you’ll have … Read more

Differentiate Nested WP_Query from Parent

You could check if the current post ID is the same as the ‘queried object’ ID, which is whichever post the current URL represents, and is separate from the current post within the loop. If both those IDs are the same then you can assume that the current content being filtered is for the content … Read more

strip_tags in get_the content

$content = get_the_content(); // regex (fixed) replacing ‘<embed>’ with ‘(embed )’ $content = preg_replace(“/<embed?[^>]+>/i”, “(embed) “, $content); // remove all tags $content = wp_strip_all_tags($content); echo $content; Edited according to the first comment: What you are trying to remove are not tags, these are HTML character entities. E. g., <p> was converted to &lt;p&gt; by WordPress … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)