if CPT content is empty then
if CPT content is empty then
if CPT content is empty then
with the_content filter hook you can modify the content using PHP preg_replace search and replace function remove_specific_wrapper($content) { $content = preg_replace(‘#<div[^>]*id=”some_id”[^>]*>.*?</div>#is’, ”, $content); return $content; } add_filter(‘the_content’, ‘remove_specific_wrapper’);
According to their site: This is not an error. in our template we have coded if content exist then the_content function call otherwise skip the_content function. So it’s necessary to add some text in the page content area then you can use your page builder plugin and the error should be gone. Not the best … Read more
it should work like this. function filter_ptags_on_images($content) { $content = preg_replace(‘/<p>\s*?((<a.*?>)?<img[^>]+class=”[^\”]*aligncenter[^\”]*”.*?>(<\/a>)?)?\s*<\/p>/’, ‘$1’, $content); return $content; } it filters if the img tag has the class aligncenter and any class.
You better call it before returning, inside technig_content() so that it’s return value is always balanced. So, the last two lines of your function would become: $content = str_replace(‘]]>’, ‘]]>’, $content); $content = balanceTags( $content ); return $content; Having said that, I don’t think it’s a good way of handling your output, since you don’t … Read more
Check out the examples on the setup_postdata Codex page. You must pass a reference to the global $post, it won’t work with any other variable. global $post; // make sure we’re working with the global. $post = $get_train; // or assign get_post result directly to $post. setup_postdata( $post ); // this must be the global … Read more
Can I add content before post content without using the_content filter
If the pages that are giving errors have no content, you can deal with it by adding a check at the start of the function: function image_manipulation( $content ) { if(empty($content)) return $content; //rest of the code }
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
The normal way to do this would be to use the_excerpt() instead of the_content() in your archive templates, then use this filter the change the number of words that appear in the excerpt: function wpse_280633_excerpt_length() { return 20; } add_filter( ‘excerpt_length’, ‘wpse_280633_excerpt_length’ ); If you want to stick with what you’ve got and not apply … Read more