Title: Content_limit Functions.php Include Custom Field Key
Last modified: August 21, 2016

---

# Content_limit Functions.php Include Custom Field Key

 *  Resolved [msmgking](https://wordpress.org/support/users/msmgking/)
 * (@msmgking)
 * [13 years ago](https://wordpress.org/support/topic/content_limit-functionsphp-include-custom-field-key/)
 * I’m using the below on home page & archive pages to limit the post content character
   count beside a thumbnail image.
 * This works great and as expected. However now I’m participating in a weekly post
   series which is wordless and only contains images. So as to keep the layout the
   same I would like to use a custom field on a per post basis to create my own 
   teaser text. I can not get the syntax correct to make the custom field show up
   where I want it.
 * This is all in the theme’s functions.php by the way.
 * Can someone please point me in the correct direction I’ve read until my eyes 
   cross and still must be looking right past it.
 *     ```
       <?php function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
           $content = get_the_content($more_link_text, $stripteaser, $more_file);
           $content = apply_filters('the_content', $content);
           $content = str_replace(']]>', ']]>', $content);
           $content = strip_tags($content);
   
          if (strlen($_GET['p']) > 0) {
             echo "<p>";
             echo $content;
             echo " <a href='";
             the_permalink();
             echo "'>"."[Read More]</a>";
             echo "</p>";
          }
          else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
               $content = substr($content, 0, $espacio);
               $content = $content;
               echo "";
               echo $content;
               echo " [...]";
               echo "<p class='readmore'><a href='";
               the_permalink();
               echo "'>".$more_link_text."</a>";
               echo "</p>";
          }
          else {
            echo $content;
               echo "Let's replace this text with a custom field";
               echo "<p class='readmore'><a href='";
               the_permalink();
             echo "'>"."[Read More]</a>";
             echo "</p>";
          }
       }
       ?>
       ```
   
 * This is the text I would like to replace with my custom field key:
 * >  echo “Let’s replace this text with a custom field”;

Viewing 1 replies (of 1 total)

 *  Thread Starter [msmgking](https://wordpress.org/support/users/msmgking/)
 * (@msmgking)
 * [13 years ago](https://wordpress.org/support/topic/content_limit-functionsphp-include-custom-field-key/#post-3781110)
 * Solved it, just had to keep working on it!
 * In case someone else may want to do something similar I’ll post the solution 
   below.
 *     ```
       else {
          		global $wp_query;
       		$postid = $wp_query->post->ID;
               echo get_post_meta($postid, 'custom-field-name', true);
       		echo " [...]";
               echo "<p class='readmore'><a href='";
               the_permalink();
             echo "'>"."[Read More]</a>";
             echo "</p>";
          }
       }
       ?>
       ```
   
 * The parts added/modified from what I was working with and previously posted:
 * >  global $wp_query;
   >  $postid = $wp_query->post->ID; echo get_post_meta($postid,‘
   > custom-field-name’, true);

Viewing 1 replies (of 1 total)

The topic ‘Content_limit Functions.php Include Custom Field Key’ is closed to new
replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)

 * 1 reply
 * 1 participant
 * Last reply from: [msmgking](https://wordpress.org/support/users/msmgking/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/content_limit-functionsphp-include-custom-field-key/#post-3781110)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
