Open Specific Button Links In a New Window Or Same Window

The PHP code in this download folder enables you to add one or 2 buttons on all single posts & pages without modifying the HTML for each button link.

You can also add a unique link for each button and specify which button links open in the same or new window. If not specified, button links will open in the same window.

Open Button Links in New or Same Window

Note : The solution you see in the demo video uses custom fields native to WordPress. If you prefer using a plugin like ACF, read the last section at the end of this tutorial to learn how to easily setup ACF to control your button elements.

Demo Video

Shows you how to setup custom fields in WordPress so you can add 1 or more buttons with custom button text and custom links to open in the same or a new window in Genesis child theme.

Tested using the Essence Pro child theme by StudioPress however will work in any Genesis child theme or any WordPress theme if you change the essence_entry_header hook to any theme specific or WordPress hook.

Installation Steps

There’s 2 steps :

  1. # Copy & paste the PHP code ( without the opening PHP tag ) to the end of your child themes functions.php file.
  2.  

  3. # Create custom fields for each button using the custom field keys seen in the following screenshot and demo video.
  4.  

Download Folder

Custom Fields for Buttons

Buttons are only displayed if each custom field key button_primary_text and/or button_text has a text value otherwise none shown.

By default, links open in the same window and only open in a new window if each custom field key primary_window and/or secondary_window have a value of 1 as seen in the screenshot above.

Using Advanced Custom Fields (ACF)

Install the free or premium version of the ACF plugin and import the file named 107304-acf.json. You can then use the stylised fields on any single Edit screen to configure your buttons.

This allows you to use ACF to open links in the same window or a new window.

Related Tutorials

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.