WordPress - 自定义摘录打印<a> text inside a <p> when it shouldn&#39;t

时间:2016-06-05 05:52:53

标签: php wordpress

I may need to work on the titling of this.

I have a function:

function excerpt($limit) {
        $excerpt = explode(' ', get_the_excerpt(), $limit);
        if (count($excerpt)>=$limit) {
            array_pop($excerpt);
            $excerpt = implode(" ",$excerpt).'...';
          } else {
            $excerpt = implode(" ",$excerpt);
          } 
        $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
        return $excerpt;
    }

And I'm calling it with <?php echo excerpt(25);?>. This is what my HTML looks like:

<div class="recent-meta-excerpt">
                            <?php echo excerpt(25);?>
                            <a class="read-more" href="<?php the_permalink(); ?>">Read More <i class="fa fa-long-arrow-right"></i></a>
                        </div>

It's outputting like this:

<div class="recent-meta-excerpt">
   <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout....                           <a class="read-more" href="http://www.stepyouraimup.com/blog/no-featured-image/">Read More <i class="fa fa-long-arrow-right"></i></a>
   </p>
</div>

But I don't want the <a> inside. When I'm calling the excerpt the <a> isn't even inside so I'm not sure how it's being wrapped in a <p>.

0 个答案:

没有答案