-3

Hello I have the following problem: I have my website made in Wordpress, and I have a 3D Cover Carousel plugin there, which shows me a gallery of photos in 3d. The thing is that when I click on the image I want the link to be opened in a NEW tab. In the plugin settings there are no such an option. The plugin html is a short code added to my page. So the only thing I can change is Additional css. So is there any options to make a link be opened in a new tab only with css?

Arina
  • 92
  • 1
  • 7
  • 3
    No...CSS can't initiate actions. It only **styles** elements. You need JS. Also forcing a new tab is not to be encouraged. It should be left to the user's preprogative. – Paulie_D Jun 14 '19 at 10:31
  • i know but i dont decide this.. – Arina Jun 14 '19 at 11:00
  • None of us have the power to decide that. Only W3C does :) – nimsrules Jun 14 '19 at 11:37
  • Does this answer your question? [Add target="\_blank" in CSS](https://stackoverflow.com/questions/17281486/add-target-blank-in-css) – c69 Feb 10 '20 at 17:08
  • Google "reverse tabnabbing" to learn about the hazard of automatically opening links in new tabs. And the fix for it. – harborsparrow Mar 19 '22 at 13:04

2 Answers2

3

As it was previously stated here, there is no way to do this with pure CSS.

If you can use JavaScript, you can target the item and add it the attribute target="_blank".

document.getElementById("element").setAttribute("target", "_blank");

Aerra
  • 72
  • 2
  • 19
  • But where do i add javascript in Wordpress? – Arina Jun 14 '19 at 10:59
  • I'm not so familiar with wordpress, see if [this](https://premium.wpmudev.org/blog/learn-how-to-add-custom-javascript-to-wordpress-the-right-way/) or [this](https://www.wpbeginner.com/wp-tutorials/how-to-easily-add-javascript-in-wordpress-pages-or-posts/) helps. – Aerra Jun 14 '19 at 11:08
  • okay i have entered in FTP and into plugin directory and changed the custom.js and it worked! – Arina Jun 14 '19 at 12:01
1
document.getElementById("element").setAttribute("target", "_blank"); 

You can add this piece of js in your footer.php file.

Another method is to add a js file and include it using wp_enqueue_script function in your function.php file.

Vintage Coders
  • 162
  • 1
  • 4