How to ensure “the_content” filter runs only for the main displayed content?

Try adding a condition to your filtering function that checks your post type against get_post_type. if ( ‘book’ == get_post_type() ) If you wish to apply this filter to pages as well, try is_singular() and include your custom post type(s) as an argument. is_singular(‘book’); This will return true if any of the following conditions are … Read more

Getting a div content of a post in wordpress?

Using DOMDocument and DOMXPath you could try this. <?php while (have_posts()) : the_post(); ob_start(); // run the_content() through the Output Buffer the_content(); $html = ob_get_clean(); // Store the formatted HTML $content = new DomDocument(); // Create a new DOMDocument Object to work with our HTML $content->loadHTML( $html ); // Load the $html into the new … Read more

Word limit in post_content after more tag

Use wp_trim_words function to limit the content to a certain number of words and returns the trimmed text. Example use of wp_trim_words function. <?php $content = get_the_content(); $trimmed_content = wp_trim_words( $content, 50, NULL ); echo $trimmed_content; ?> So I added wp_trim_words function in your code to get 50 words after <!– more –>. <?php $after_more … Read more

apply_filters(‘the_content’, $content) alternative

The Core filters on the_content are: 131 add_filter( ‘the_content’, ‘wptexturize’ ); 132 add_filter( ‘the_content’, ‘convert_smilies’ ); 133 add_filter( ‘the_content’, ‘convert_chars’ ); 134 add_filter( ‘the_content’, ‘wpautop’ ); 135 add_filter( ‘the_content’, ‘shortcode_unautop’ ); 136 add_filter( ‘the_content’, ‘prepend_attachment’ ); You can apply whichever of those you’d like to any string you’d like. The second parameter is the name … Read more

the_content and wp_link_pages

I guess you have: the_content(); wp_link_pages(); in your theme file. So you can instead try the following (PHP 5.4+): /** * Append the wp_link_pages to the content. */ ! is_admin() && add_filter( ‘the_content’, function( $content ) { if( in_the_loop() ) { $args = [ ‘echo’ => false ]; // <– Adjust the arguments to your … Read more

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