0

I can hardly believe this is happening, but I have

if ($text == "") {
     $text = get_the_excerpt();
    //  $text = "this will be the text";
}

When I call echo $text subsequently with the simple string (now commented out), then I get that string, but when I use get_the_excerpt then the_title above and $text get wrapped in a link to the post (see ** below). Any idea how I can prevent this?

<div class="col-sm-4">
    <div class="card card--big">
        <a href="<?php the_permalink(); ?>">
            <article <?php post_class(); ?>>

                <div class="card__image" style="background-image:url(<?php echo $image[0]; ?>")> </div>

                <div class="card__text">
                    <h4>
                       <?php the_title(); ?>
                    </h4>
                    <?php 
                        echo $text; 
                    ?>
                </div>
            </article>
        </a>
    </div>
</div>

And this is what comes out

<div class="card card--big">
        <a href="//localhost:3000/2016/amsterdam-tapas-barra-pikoteo/">
            **</a>**<article class="post-5261 post type-post status-publish format-standard has-post-thumbnail hentry category-restaurant-reviews">
**<a href="//localhost:3000/2016/amsterdam-tapas-barra-pikoteo/">**

                <div class="card__image" style="background-image:url(//localhost:3000/wp-content/uploads/2016/05/Pikoteo-tapas-Amsterdam.jpg" )=""> </div>

                **</a>**<div class="card__text">**<a href="//localhost:3000/2016/amsterdam-tapas-barra-pikoteo/">**
                    <h4>
                       Amsterdam tapas, traditional and modern: Barra and Pikoteo                    </h4>
                    A long time ago____ 
                    **</a>**
                    <a href="//localhost:3000/2016/amsterdam-tapas-barra-pikoteo/">[…]</a>
            </div>
         </article>            
    </div>

I'm using OSX, MAMP and no plugins

  • @N00b - interesting question, as if inject the $text elsewhere there is no problem. I've added the full html. – Simon H May 9 '16 at 18:22
  • You are wrapping the whole thing with <a> tag. Everything inside it is a link. – N00b May 9 '16 at 18:22
  • What exactly do you want to be a link? Whole <article> is currently a link. – N00b May 9 '16 at 18:25
  • 1
    It depends what HTML is being used: in HTML5 you can put pretty much anything inside <a> tag that isn't interactive (e.g other links or buttons). – N00b May 9 '16 at 19:09
  • 1
    Are you seeing the extra anchor tags in the actual source of the page or via a browser inspection tool? Chrome will interpret your code and, in certain conditions, add missing closing tags or insert code you didn't write (<tobdy> anyone?). Wrapping the entire article with an anchor could possibly cause this. – jdm2112 May 9 '16 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.