Home › Forums › Front-end Issues › Button on front end website › Reply To: Button on front end website
Add this to your single.php file where you want your button to appear:
if (get_field('show_external_link_button')) { ?>
<a class="post-button" href="<?php the_field('external_link_button_url') ?>"><?php the_field('external_link_button_label') ?></a><?php
}
Remember that this code needs to be inside a PHP code block. This will create a link with external_link_button_label
as the label and external_link_button_url
as the target.
To style the link as button add this snippet to your CSS file:
.post-button {
background-color: #4CAF50; /* Green background */
color: white; /* White text */
border: none; /* No border */
padding: 15px 32px; /* Padding */
text-align: center; /* Center the text */
text-decoration: none; /* No underline */
display: inline-block; /* Display on the same line */
font-size: 16px; /* Increase font size */
}
You can play around with the values to match your website’s styles.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.