Function to shorten string without cutting off last word

There are various ways to achieve this as listed following. Using wordwrap() function : function shortened_description($cutlength) { $content = get_field(‘event_short_description’); $charcount = strlen($content); $content = wordwrap($content, 28); $content = explode(“\n”, $content); $shorter = $content[0]; if ($charcount >= $cutlength) { echo $shorter . ‘… <a href=”‘ . get_permalink() . ‘”>more ></a>’; } //$charcount >= $cutlength else … Read more

Issues with the excerpt (wordcount/HTML/images)

Answer on my own question (without using a plugin and choosing a middle way) for what we want to achieve. Because the template has also a code starting with: if ( has_post_thumbnail() && ( $post->post_type == ‘post’ ) ) we have taken that part of code away. (we won’t used it in postings/pages, therefore) Following … Read more

How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?

The get_template_part(‘content’, get_post_format()); line includes content from one of the other files in your theme based on the post type, the file name will be something like content-page.php (or content.php if the format is not found). If you print out what get_post_format() returns, you will be able to tell which content file to look into. … Read more

Merging two excerpt functions to work with conditions

Depending on where in the loop you call excerpt() wpautop might be creating the <p>…</p> wrapper. In that case, you could wrap $excerpt with <p>…</p> before returning it. Edit: Try this approach <?php echo excerpt(25).”\n”;?> (or possibly “\n\n”) to change the behavior. in function awesome_excerpt() you have $text = substr( $content, 0, strpos( $content, ‘</p>’ … Read more

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