-
Posted in : Responsy WP
-
Is it possibile to have a link opening in a new tab (target=”_blank”) using the button shortcode [button] as anchor? How can I do this?
Thanks in advance for letting me know.
Mirko
Add
targetparameter to [button] shortcode:– Go to Appearance > Editor > functions.php,
– Find [button] shortcode code lines:
function button( $atts, $content = null ) { extract( shortcode_atts( array( 'button_text' => 'Button', 'bold_text' => '', 'button_type' => 'btn-default', 'button_size' => '', 'button_link' => '#' ), $atts ) ); if ( $bold_text == "yes" ) { $button_text_out = "<b>$button_text</b>"; } else { $button_text_out = "$button_text"; } $button = '<a class="btn ' . $button_type . ' ' . $button_size . '" href="' . $button_link . '">' . $button_text_out . '</a>'; return $button; } add_shortcode('button', 'button');– Add the parameter:
function button( $atts, $content = null ) { extract( shortcode_atts( array( 'button_text' => 'Button', 'target' => "", 'bold_text' => '', 'button_type' => 'btn-default', 'button_size' => '', 'button_link' => '#' ), $atts ) ); if ( $bold_text == "yes" ) { $button_text_out = "<b>$button_text</b>"; } else { $button_text_out = "$button_text"; } $button = '<a ' . $target . ' class="btn ' . $button_type . ' ' . $button_size . '" href="' . $button_link . '">' . $button_text_out . '</a>'; return $button; } add_shortcode('button', 'button');
Button shortcode:
[button target="_blank" button_text="My button" button_link="http://www.example.com"]
Hi Mehmet, thanks for your answer, I have some issues:
1) I don’t see the functions.php file in Appearance > Editor > functions.php, and I’ve edited the file with Notepad++. Do you know how can I have the functions.php file visible in the Appearance section?
2) I’ve added the parameter above to the functions.php and updated the button shortcode, but it don’t work and the link still opens on the same tab. Was the solution tested? I’m sure that I followed your instructions, so I was wondering if there’s some other code to add or some other things I have to do, or another way to get this solved.
Let me know if you can help. Many thanks,
Mirko
p.s. however
– I see the functions.php,
– add the new parameter in usage:
[button target="_blank" button_text="My button" button_link="http://www.example.com"]– Add the parameter:
function button( $atts, $content = null ) { extract( shortcode_atts( array( 'button_text' => 'Button', 'new_tab' => "", 'bold_text' => '', 'button_type' => 'btn-default', 'button_size' => '', 'button_link' => '#' ), $atts ) ); if ( $bold_text == "yes" ) { $button_text_out = "<b>$button_text</b>"; } else { $button_text_out = "$button_text"; } $button = '<a ' . $new_tab. ' class="btn ' . $button_type . ' ' . $button_size . '" href="' . $button_link . '">' . $button_text_out . '</a>'; return $button; } add_shortcode('button', 'button');
Button shortcode:
[button new_tab="target='_blank'" button_text="My button" button_link="http://www.example.com"]
The forum ‘Responsy WP’ is closed to new topics and replies.