admin管理员组文章数量:1026989
I am trying to use the ACF URL field to wrap a card component inside a url, then use the same url inside of this component in a button, this is because of styled reasons in the CSS.
This is my code:
<a href="<?php the_field('first_featured_url'); ?>">
<div class="cell medium-auto card">
<span class="card__title"><?php the_field('first_featured_title'); ?></span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(<?php echo get_field('first_featured_image'); ?>);">></div>
</div>
<div class="card__footer">
<a href="<?php the_field('first_featured_url'); ?>"><?php the_field('first_featured_link_text'); ?></a>
</div>
</div>
</a>
But then what I get rendered is:
<a href="correcturl">
</a>
<div class="cell medium-auto card"><a href="correcturl">
<span class="card__title">Featured Client</span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(aurl);">></div>
</div>
<div class="card__footer">
<a href="correcturl">
</a><a href="correcturl">View Our Clients</a>
</div>
</div>
Somehow it works, the component is clickable and it works as expected but I'm not sure why it is duplicating the link in the footer and not able to wrap my component. Is this behavior expected? Can I do something to prevent it?
Thank you.
I am trying to use the ACF URL field to wrap a card component inside a url, then use the same url inside of this component in a button, this is because of styled reasons in the CSS.
This is my code:
<a href="<?php the_field('first_featured_url'); ?>">
<div class="cell medium-auto card">
<span class="card__title"><?php the_field('first_featured_title'); ?></span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(<?php echo get_field('first_featured_image'); ?>);">></div>
</div>
<div class="card__footer">
<a href="<?php the_field('first_featured_url'); ?>"><?php the_field('first_featured_link_text'); ?></a>
</div>
</div>
</a>
But then what I get rendered is:
<a href="correcturl">
</a>
<div class="cell medium-auto card"><a href="correcturl">
<span class="card__title">Featured Client</span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(aurl);">></div>
</div>
<div class="card__footer">
<a href="correcturl">
</a><a href="correcturl">View Our Clients</a>
</div>
</div>
Somehow it works, the component is clickable and it works as expected but I'm not sure why it is duplicating the link in the footer and not able to wrap my component. Is this behavior expected? Can I do something to prevent it?
Thank you.
Share Improve this question asked Mar 21, 2019 at 20:25 SergiSergi 2601 gold badge6 silver badges18 bronze badges1 Answer
Reset to default 1It's actually an HTML issue, not an ACF one.
You can't have nested "a" tags.
If you do, browsers try to rationalize things by closing them for you and generally making a mess of what you were trying to do.
You probably don't need the inner one anyways, the whole element is going to be clickable.
I am trying to use the ACF URL field to wrap a card component inside a url, then use the same url inside of this component in a button, this is because of styled reasons in the CSS.
This is my code:
<a href="<?php the_field('first_featured_url'); ?>">
<div class="cell medium-auto card">
<span class="card__title"><?php the_field('first_featured_title'); ?></span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(<?php echo get_field('first_featured_image'); ?>);">></div>
</div>
<div class="card__footer">
<a href="<?php the_field('first_featured_url'); ?>"><?php the_field('first_featured_link_text'); ?></a>
</div>
</div>
</a>
But then what I get rendered is:
<a href="correcturl">
</a>
<div class="cell medium-auto card"><a href="correcturl">
<span class="card__title">Featured Client</span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(aurl);">></div>
</div>
<div class="card__footer">
<a href="correcturl">
</a><a href="correcturl">View Our Clients</a>
</div>
</div>
Somehow it works, the component is clickable and it works as expected but I'm not sure why it is duplicating the link in the footer and not able to wrap my component. Is this behavior expected? Can I do something to prevent it?
Thank you.
I am trying to use the ACF URL field to wrap a card component inside a url, then use the same url inside of this component in a button, this is because of styled reasons in the CSS.
This is my code:
<a href="<?php the_field('first_featured_url'); ?>">
<div class="cell medium-auto card">
<span class="card__title"><?php the_field('first_featured_title'); ?></span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(<?php echo get_field('first_featured_image'); ?>);">></div>
</div>
<div class="card__footer">
<a href="<?php the_field('first_featured_url'); ?>"><?php the_field('first_featured_link_text'); ?></a>
</div>
</div>
</a>
But then what I get rendered is:
<a href="correcturl">
</a>
<div class="cell medium-auto card"><a href="correcturl">
<span class="card__title">Featured Client</span>
<div class="card__image__wrap">
<div class="card__image" style="background-image: url(aurl);">></div>
</div>
<div class="card__footer">
<a href="correcturl">
</a><a href="correcturl">View Our Clients</a>
</div>
</div>
Somehow it works, the component is clickable and it works as expected but I'm not sure why it is duplicating the link in the footer and not able to wrap my component. Is this behavior expected? Can I do something to prevent it?
Thank you.
Share Improve this question asked Mar 21, 2019 at 20:25 SergiSergi 2601 gold badge6 silver badges18 bronze badges1 Answer
Reset to default 1It's actually an HTML issue, not an ACF one.
You can't have nested "a" tags.
If you do, browsers try to rationalize things by closing them for you and generally making a mess of what you were trying to do.
You probably don't need the inner one anyways, the whole element is going to be clickable.
本文标签: advanced custom fieldsACF URL behaviorduplicating links
版权声明:本文标题:advanced custom fields - ACF URL behavior, duplicating links 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745667529a2162260.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论