Getting content from a referenced post

Function get_the_content doesn’t take post_ID as param. It has 2 params: $more_link_text – (string) (optional) Content for when there is more text. $stripteaser – (boolean) (optional) Strip teaser content before the more text. So you can’t use it as in your code get_the_content( $p->ID ); – this will get content of current post and use … Read more

Omit image captions from get_the_content()

It turned out that the method called strip_tags(preg_replace(” (\[.*?\])”, ”, $output)) before strip_shortcodes($output), which caused aforementioned issue, since the code removed shortcode in square brackets, but retained contained image captions. I could fix it by swapping the two method calls like this: $output = get_the_content(); $output = strip_shortcodes($output); // Strip WordPress shortcodes first! $output = … Read more

Add a div of content within the_content after a certain block

Yes, add_filter() is what you’re looking for, but to identify a specific block, you want the render_block hook. <?php add_filter(‘render_block’, function($block_content, $block) { // Only for Core Code blocks if(‘core/code’ === $block[‘blockName’]) { // Add your custom HTML after the block $block_content = $block_content . ‘<div>Test addition</div>’; } // Always return the content return $block_content; … Read more

How to debug this search & replace strings snippet?

Notice the if ( is_page() line. It’s to indicate that the snippet only works with pages, not posts. Pull it out of the if condition if you want to apply it site-wide. function wpdocs_replace_content( $text_content ) { $text = array( ‘chamber’ => ‘<strong>chamber</strong>’, ); $text_content = str_ireplace( array_keys( $text ), $text, $text_content ); return $text_content; … Read more

Problem on the_excerpt(); function

Assuming that you want the full post content to appear only on single blog posts, and that you want the post excerpt to appear everywhere else, try something like this inside your Loop in index.php: <?php if ( is_singular() ) { the_content( ‘Read More’ ); } else { the_excerpt(); } ?> Additional Codex reading: the_content() … Read more

Get URL from shortcode tag

There’s no need to use regex for this. WordPress has a Shortcode API to do this work for you. That codex page includes one of my favorite codex code snippets: function bartag_func( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘something’, ‘bar’ => ‘something else’, ), $atts ) ); … Right at the start of … Read more

the_excerpt() in content.php and get_template_part() in single.php

the_content() does not grab the PHP file content.php, it simply displays a Post’s content. Likewise, the_excerpt() grabs the excerpt of a post. get_template_part simply finds a file within your theme named whatever you put in, with an optional suffix. get_template_part( ‘content’ ); // content.php get_template_part( ‘content’, ‘my_page’ ); // content-my_page.php in order for make different … Read more

The Content is not Wraping in tag

The function the_content() prints the content with a p tag itself. I mean, if you use echo ‘<p class=”our_p”>’ . the_content() . ‘</p>; It actually outputs- <p class=”our_p”><p>lorem ipsum dolor sit amet…</p></p> Use get_the_content() instead. It will return the unfiltered content. Something link this- echo ‘<p class=”our_p”>’ . get_the_content() . ‘</p>; Codex: https://codex.wordpress.org/Function_Reference/the_content

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