Skip to content

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

Notifications You must be signed in to change notification settings

cyberwani/acf-smart-button

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

It always returns the url as the same field, wheter its the internal or external link. With button.target you can additionaly add target="_blank" in your template without additional casing.

alt tag

alt tag

Example (twig style):

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

Isn't that lean =)?

Output / Return

When Internal

[text] => I am an internal Buttonse
[url] => http://yoursite.dev/selected-page
[target] => ''

When External

[text] => I am an external Buttonse
[url] => http://kollektiv.ag
[target] => 'target="blank"'

Future Plans

  • option to select allowed post_types for post_object selector
  • language support
  • validate url field
  • cleanups etc.
  • eventually acf4 support

Compatibility

This add-on works only with version 5 and up.

Installation

This add-on can be treated as both a WP plugin and a theme include.

Install as Plugin

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

Include within theme

  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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 79.1%
  • JavaScript 11.1%
  • CSS 9.8%