Last active
February 13, 2019 21:51
-
-
Save moxdev/1f1327c567e59e8ccd795bec8aef9110 to your computer and use it in GitHub Desktop.
ACF Contact Info #wp #acf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this to functions.php acf options page | |
acf_add_options_sub_page( | |
array( | |
'page_title' => 'Contact Information', | |
'menu_title' => 'Contact Info', | |
'menu_slug' => 'contact-information', | |
'post_id' => 'contact-information', | |
'parent_slug' => 'global-information', | |
) | |
); | |
// Add function where you want it | |
if ( ! function_exists( 'slug_contact_info' ) ) : | |
/** | |
* Output contact info from ACF | |
* | |
* @return void | |
*/ | |
function slug_contact_info() { | |
if ( function_exists( 'acf_add_options_page' ) ) { | |
$name = get_field( 'company_name', 'contact-information' ); | |
$add1 = get_field( 'address_1', 'contact-information' ); | |
$add2 = get_field( 'address_2', 'contact-information' ); | |
$city = get_field( 'city', 'contact-information' ); | |
$state = get_field( 'state', 'contact-information' ); | |
$zip = get_field( 'zip', 'contact-information' ); | |
$phone = get_field( 'phone', 'contact-information' ); | |
$fax = get_field( 'fax', 'contact-information' ); | |
$email = get_field( 'email', 'contact-information' ); | |
if ( $name || $add1 || $add2 || $city || $state || $zip || $phone || $fax || $email ) : | |
?> | |
<div itemscope itemtype="http://schema.org/Organization" class="contact-info"> | |
<?php if ( $name || $add1 ) : ?> | |
<div class='address-section'> | |
<?php if ( $name ) : ?> | |
<span itemprop="name" class='company-name'> | |
<?php | |
echo wp_kses( | |
$name, | |
array( | |
'sup' => array(), | |
) | |
); | |
?> | |
</span><!-- company-name --> | |
<br /> | |
<?php endif; ?> | |
<?php if ( $add1 ) : ?> | |
<span itemprop="address"> | |
<span itemprop="streetAddress" class="street-address"> | |
<?php | |
echo esc_html( $add1 ) . '<br>'; | |
if ( $add2 ) : | |
echo esc_html( $add2 ) . '<br>'; | |
endif; | |
?> | |
</span><!-- street-address--> | |
<?php if ( $city ) : ?> | |
<span itemprop="addressLocality" class="city"> | |
<?php | |
echo esc_html( $city ); | |
if ( $state || $zip ) { | |
echo ', '; | |
} | |
?> | |
</span><!-- city--> | |
<?php endif; ?> | |
<?php if ( $state ) : ?> | |
<span itemprop="addressRegion"class="state"> | |
<?php echo esc_html( $state ); ?> | |
</span><!-- state--> | |
<?php endif; ?> | |
<?php if ( $zip ) : ?> | |
<span itemprop="postalCode" class="zip"> | |
<?php echo ' ' . esc_html( $zip ); ?> | |
</span><!-- zip--> | |
<?php endif; ?> | |
</span><!-- address --> | |
<?php endif; ?> | |
</div><!-- address-section --> | |
<?php endif; ?> | |
<?php if ( $phone || $fax || $email ) : ?> | |
<?php if ( $phone ) : ?> | |
<span itemprop="telephone" class="phone">Phone: <a class="tel" href="tel:<?php echo esc_attr( $phone ); ?>"><?php echo esc_html( $phone ); ?></a></span> | |
<?php endif; ?> | |
<?php if ( $fax ) : ?> | |
<span itemprop="faxNumber" class="fax">Fax: <?php echo esc_html( $fax ); ?></span> | |
<?php endif; ?> | |
<?php if ( $email ) : ?> | |
<span itemprop="email" class="email"><a href="mailto:<?php echo esc_attr( $email ); ?>" class="ftr-email"><?php echo esc_html( $email ); ?></a></span> | |
<?php endif; ?> | |
<?php endif; ?> | |
</div><!-- contact-info --> | |
<?php | |
endif; | |
} | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment