Saturday, May 21st, 2022

Open specific button link in a new window or same window

The PHP code in this downloads folder enables you to add one or 2 buttons to all single posts and 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.

pay attention : The solution you see in the demo video uses WordPress’ native custom fields. If you prefer to use 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 that you can add 1 or more buttons with custom button text and custom links, or open a new window in the Genesis child theme.

Tested by StudioPress using Essence Pro child theme, however if you change it will work in any Genesis child theme or any WordPress theme. essence_entry_header Hooks for any theme specific or WordPress hook.

installation steps

There are 2 steps:

  1. # Copy and paste the PHP code (without the opening PHP tag) at the end of your child theme functions.php file.
  2. # Create custom fields for each button using the custom field keys as seen in the following screenshot and demo video.

download folder

custom field for button

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

By default, links open in the same window and only open in a new window if each custom field is keyed. primary_window and/or secondary_window Has 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 stylized fields on a 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

Source link