Do_shortcode question

Apologies in advance for what is no doubt a newbie question but I’m editing a WordPress theme and need to get a button to open in a new tab when someone clicks on it. Usually to do this it would be target="_blank". However, in the theme it has the following code:

<?php echo do_shortcode('[CBUTTON]'); ?>

Do I somehow edit this directly or do I need to work back to find a file with all the shortcuts in it?

Thanks in advance.

Yeah you need to find the CBUTTON shortcode. It will either being in a shortcodes file or defined in functions.php for the theme. Just look around in the theme. Once you find it, you should see the typical link code that will allow you to add the target="_blank" piece.

HOWEVER, usually it is a bad idea to directly edit the theme code if you think the theme is going to get updated at some point. It will overwrite your changes. When you do find the shortcode function, see if perhaps it takes any parameters. If it does, one of them might be to set the button to open in a new tab.

Maybe even ask the author if it is possible to add that as a feature, or if it is on github, make a pull request to change it. That way if they do update the theme in the future, it will have a way for you to do the new tab on click and keep your change in there. :slight_smile:

Thanks @Martyr2 , I’ll have a look.

I omitted to mention that I’ve created a child theme for any changes I’m making so that they don’t get overwritten when the theme is updated.

I’ve mentioned this feature to the developer; hoping they just amend in their next update as it would be expected behaviour from the button not just something that is my personal preference.

Thanks again, really appreciate you taking the time to respond.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.