2017 © Pedro Peláez
 

wordpress-plugin acf-smart-button

A simple, clean and lean acf Field for internal and external links.

image

gillesgoetsch/acf-smart-button

A simple, clean and lean acf Field for internal and external links.

  • Thursday, August 17, 2017
  • by gillesgoetsch
  • Repository
  • 4 Watchers
  • 58 Stars
  • 5,991 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 11 Forks
  • 4 Open issues
  • 3 Versions
  • 10 % Grown

The README.md

ACF Smart Button

A simple, clean and lean ACF Field that allows the user to select an internal link as a post_object or an external link as a url field via a smooth toggle., (*1)

It always returns the url as the same field, whether it's an internal or external link. With button.target you can additionally add target="_blank" in your template without additional casing., (*2)

alt tag, (*3)

alt tag, (*4)

Example (twig style):, (*5)

{% if button %}   
  <a href="{{ button.url }}" {{button.target }}>{{ button.text }}</a>   
{% endif %}

Isn't that lean =)?, (*6)

Example (vanilla PHP):, (*7)

if ( get_field( 'acf_button_field' ) ) :
  $button = get_field( 'acf_button_field' );
  $button_label = $button['text'];
  $button_url = $button['url'];
  $button_target = $button['target'];
endif;

Output / Return

When Internal

[text] => I am an internal button
[url] => http://yoursite.dev/selected-page
[target] => '', (*8)

When External

[text] => I am an external button
[url] => http://kollektiv.ag
[target] => 'target="blank"', (*9)

Note: In both cases the field data will only be returned if the button text is set in combination with a target. If either one is missing, there will be no data returned., (*10)

Future Plans

  • ~~option to select allowed post_types for post_object selector~~ 7626ad4
  • language support
  • validate url field
  • cleanups etc.
  • ~~eventually acf4 support~~ (no?)

Compatibility

This add-on works only with version 5 and up., (*11)

Installation

This add-on can be treated as both a WP plugin and a theme include., (*12)

Install as Plugin, (*13)

  1. Copy the 'acf-button' folder into your plugins folder
  2. Activate the plugin via the Plugins admin page

Include within theme, (*14)

  1. Copy the 'acf-smart-button' folder into your theme folder (can use sub folders). You can place the folder anywhere inside the 'wp-content' directory
  2. Edit your functions.php file and add the code below (Make sure the path is correct to include the acf-button.php file)
include_once('acf-smart-button/acf-smart-button.php');

Else

Partially inspired by https://github.com/envex/acf-button-field, but is missing acf5 support and didn't meet my requirements fully., (*15)

The Versions

17/08 2017

dev-master

9999999-dev

A simple, clean and lean acf Field for internal and external links.

  Sources   Download

GPLv2

The Requires

  • php >=5.3.2

 

plugin wordpress button acf

17/08 2017

1.0.1

1.0.1.0

A simple, clean and lean acf Field for internal and external links.

  Sources   Download

GPLv2

The Requires

  • php >=5.3.2

 

plugin wordpress button acf

04/04 2017

1.0.0

1.0.0.0

A simple, clean and lean acf Field for internal and external links.

  Sources   Download

GPLv2

The Requires

  • php >=5.3.2

 

plugin wordpress button acf