• Resolved Shehryar Tanoli

    (@shehryarkhan)


    Hi i am new to plugin dev , i have created a custom post type and successfully displayed data on front end..Now i want to limit my content to 200-300 words and add anchor tag.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You could use “the_content” filter to truncate content and add an anchor tag. You could use wp_trim_words() to truncate content, but it strips out HTML to accurately count words. To keep the tags and still get an accurate count can be rather difficult.

    Using “the_content” would not stop someone from saving a lengthy post. It filters output, not what is saved. To alter what is saved, use the “wp_insert_post_data” filter.

    Thread Starter Shehryar Tanoli

    (@shehryarkhan)

    @bcworkz This is how i am able to do it.Now i am having trouble to go to a specific permalink .Permalink in the anchor tag is not working properly it does not takes me to the specific post rather it shows all posts again without styling which i have applied..

    <?php 
         if(strlen($feedback)<200) 
                {
                 echo do_shortcode("<b>Feedback </b>: ". "{$feedback}"); 
                 }
                  elseif(strlen($feedback)>200)
                   {
                    $feedback = substr(get_post_meta(get_the_ID(),'feedback',true),0,200);
                            echo do_shortcode("<b>Feedback </b>: ". "{$feedback}");
                                       ?>
                                    <div class="anchor">
                                   <a>">"> ...Read More</a>
                                    </div>
    Moderator bcworkz

    (@bcworkz)

    Oh, 200 characters (from strlen()) is a lot different than 200 words ??

    There’s not enough context in your posted code. How are you getting the permalink? The href attribute didn’t make it into your posted code. FWIW, using the post’s ID as a p= URL query string will take you to a single post regardless of permalink settings. As in https://example.com/?p=1234

    When you post code in these forums, please use the code button or demarcate with backticks. When you don’t, the forum’s parser will corrupt your code, making it unusable for testing or copying as working code. I tried to fix your code, but there wasn’t enough to work with.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding Anchor Tag’ is closed to new replies.