Wordpress ACF auto p overpopulating text field - php

I'm migrating custom wordpress templates over from an old site to a new site. In the new site one of my older templates using ACF Repeater is generating unnecessary < p > breaks between each element in my echo. Here's the source code:
<?php
if( have_rows('features_list') ):
$i=0;
while ( have_rows('features_list') ) : the_row();
echo '<p><span class="purple">+ </span>' . get_sub_field('feature_item') . '</p>';
$i++;
endwhile;
endif;
?>
The rendered HTML comes out to:
<p>
<span class="purple">+ </span>
</p>
<p>Text Content Text Content</p>
What I need it to render as and what it was in my old template is:
<p><span class="purple">+ </span> Text Content Text Content</p>
Im suspecting that Wordpress is wrapping my get_sub_field() in a < p > and therefore is closing the < span > around a < p > because of the wpautop() function. Im running Wordpress 4.5.3 and seeing this.

This has been resolved. The solution was in the Custom Fields dashboard within the specific subfield. There is an option for "New Lines" conditional formatting and by default it was set to "Automatically add paragraphs". I switched it to "none" and this fixed the problem.
Thanks

Related

Change product category heading tag for shortcode ux_product_categories on Flatsome - Woocommerce

I'm looking to change heading tag (currently H5) for product categories displaying on home page. These categories are displayed on home page by using an element named ux_product_categories on Flatsome theme.
It seems to be a shortcode. So I looked at product_categories.php file in wp-content/themes/flatsome/inc/shortcodes.
Indeed, I found H5 heading tag, however, when I change it (by putting the modified file with the same path in child theme)... Nothing happens, product categories have still H5 heading tag.
What do I missed ?
Here's the code I changed (replacing "h5" by "p") :
<div class="box-text <?php echo implode(' ', $classes_text); ?>" <?php echo get_shortcode_inline_css($css_args); ?>>
<div class="box-text-inner">
<h5 class="uppercase header-title">
<?php echo $category->name; ?>
</h5>

Wordpress use the_content() with out gallery?

Is it possible to use the_content() excluding the galleries? I want to make this because I need the gallery displayed with flexslider. I already integrate flexslider. If I want to show the content of the post, for example: some text, separated images and of course a gallery. It will display the gallery with flexslider and then the content with the text, images and the gallery again. I don't want the gallery duplicated.
<div class="entry-content">
<?php $gallery = get_post_gallery( get_the_ID(), false );?>
<div class="flexslider flexslider-gallery">
<ul class="slides slides-gallery">
<?php foreach( $gallery['src'] AS $src ){ ?>
<li>
<img alt="Gallery image" src="<?php echo $src; ?>" />
</li>
<?php } ?>
</ul> <!-- end .slides -->
</div> <!-- end .flexslider -->
<?php the_content(); ?>
</div><!-- .entry-content -->
Ok here is the solution:
Add to functions.php
function remove_shortcode_from($content) {
$content = strip_shortcodes( $content );
return $content;
}
and then call it when you need, in my case in content-gallery.php:
add_filter('the_content', 'remove_shortcode_from');
the_content();
remove_filter('the_content', 'remove_shortcode_from')
Two ways:
1) The WordPress Gallery is contained in a div with class .gallery. If flexsider does not also use that class, you could simply set your CSS to:
.gallery { display: none; }
2) You could get the content with get_the_content, parse it using a DOM parser and delete the Gallery.
Option #1 is less efficient, but avoids the complexity of parsing the DOM.
Neither method is guaranteed to work if the site is use a non-standard gallery plugin that is creating non-WP HTML.

Show exactly full content in WordPress without escape tags

I want to show limit latest post of WordPress in main page. I'm using WordPress APIs and functions to show that, but after that get_the_content() remove and escape all of seved tags and my posts don't show correctly such as editor tags.
This function escape HTML tags:
<ul style="list-style: none;margin:5px" class="latest-posts">
<!-- LOOP START -->
<?php $the_query = new WP_Query( 'showposts=3' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<!-- THIS DISPLAYS THE POST THUMBNAIL, The array allows the image to has a custom size but is always kept proportional -->
<li> <?php the_post_thumbnail( array(100,100) );?></li>
<!-- THIS DISPLAYS THE POST TITLE AS A LINK TO THE MAIN POST -->
<li>
<a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
</li>
<!-- THIS DISPLAYS THE EXCERPT OF THE POST -->
<li>
<?php echo mb_substr(get_the_content(), 0, 1200).' ...'; ?>
</li>
<!-- READ MORE LINK -->
<li>more ...</li>
<?php endwhile;?>
<!-- LOOP FINNISH -->
</ul>
There are basically three possibilities how to output the excerpt of the post content.
with the excerpt() function, to output the content of the excerpt field in post editor, if it's not filled it will display the first 55 words of the post content ( use excerpt_length filter to control the length of the excerpt ).
to use the <!--more--> quicktag, the_content() tag will only show the excerpt up to the <!--more--> quicktag. That quicktag will not work in single pages templates.
to manually strip HTML from post content and to show custom excerpt. One way to do that is to use wp_filter_nohtml_kses() function:
echo mb_substr( wp_filter_nohtml_kses( get_the_content() ), 0, 1200 );
All methods above will strip the HTML from post content. To include HTML in excerpts use excerpt field in post editor, WordPress will preserve HTML you included in post editor. There are also some plugins like Advanced Excerpt that will create excerpt from content and preserve html, but I don't believe that there is a bullet proof way of doing that.

Drupal - Display content of node

I've a problem with the content of one node.
There's a loop to display the excerpt of last news on a page.
the content of the loop is :
<h2 class="title"><?php print $title; ?></h2>
<?php if ($node->field_news_thumb[0] && $node->field_news_thumb[0]['filepath']): ?>
<img src="/<?php print $node->field_news_thumb[0]['filepath']; ?>" width="200" >
<?php endif; ?>
<?php print_r($node->content['body']['#value']); ?>
But there is just one news for which the title and thumb are well displayed, but the content is empty.
In the backoffice I've just one paragraph in content.
I found that if I add a new paragraph, the first one will be displayed on the front.
When there's just one paragraph, if I click on the title to get fullpage node. The content is well displayed with exactly the same method :
<?php print_r($node->content['body']['#value']); ?>
How can I display the full content of these nodes ?
Ok I find the solution.
I have replace
print_r($node->content['body']['#value']);
By :
$news = node_load(array('nid' => $node->nid));
print_r($news->body);
This give me the full content. I just have to shorten as I want.

Wordpress, wrap posts in div

I'm quite new to wordpress, so bear with me. I have a site up and running allowing me to add content dynamically, the only problem is styling each post. I'm looking to wrap posts in a div, so images would be wrapped in one div and text posts would be wrapped in another, if that makes sense?Here's some code I've been using:
<?php if ( in_category('photos') ) { ?>
<div id="testing">
<?php } else { ?>
<div id="test-2">
<?php } ?>
The only problem with this is that it wraps all posts in a given category and doesn't put a closing '< / div >' after the content, if that makes sense?
Well, the only reason you're not getting any closing </div>s is because you're not putting it anywhere in your php.
This should work:
<?php while( have_posts() ) : the_post()
if( in_category( 'photos' ) { ?>
<div id="testing">
// All your post content and whatnot
<?php the_content(); ?>
</div>
<?php } else { ?>
<div id="test-2">
// All your post content
<?php the_content(); ?>
</div>
<?php }
endwhile; ?>
If you don't write complete markup in your theme files, you can't possibly expect Wordpress, or PHP, to automatically close your HTML tags.
"if that makes sense" No it doesn't really make sense as Wordpress by default adds a CSS-class for every category and tag to the surrounding div. If that is not the case in your theme, use the function post_class() to add the CSS-classes to your div.
See the post_class()-documentation for usage examples.

Categories