Last active
May 2, 2020 07:38
-
-
Save aldolat/5108b338155f71c19e6b6d5f55abbdf4 to your computer and use it in GitHub Desktop.
Add attribute target="_blank" to all links children of "posts-in-sidebar" class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register scripts. | |
* Add this function to your functions.php file or to your functions plugin. | |
* | |
* @since 1.0.0 | |
*/ | |
function posts_in_sidebar_hacks() { | |
wp_register_script( | |
'pis_scripts', | |
get_stylesheet_directory_uri() . '/scripts/pis-hacks.js', | |
array( 'jquery' ), | |
'1.0.0', | |
true | |
); | |
wp_enqueue_script( 'pis_scripts' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'posts_in_sidebar_hacks' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add the `target="_blank"` attribute to Posts in Sidebar links. | |
* Activate one of them only (LINE A or LINE B), according to your needs! | |
*/ | |
jQuery(document).ready(function(){ | |
// Add the `target="_blank"` attribute to all links of Posts in Sidebar. | |
// Targets any link child of .posts-in-sidebar class. | |
// Deactivate this line, in you want line B, prepending a double slash (//) in front. | |
// Line A: | |
jQuery('.posts-in-sidebar a').attr('target','_blank'); | |
// Add the `target="_blank"` attribute only to Posts in Sidebar title links. | |
// Targets any link with .pis-title-link class. | |
// Deactivate this line, in you want line A, prepending a double slash (//) in front. | |
// Line B: | |
jQuery('a.pis-title-link').attr('target','_blank'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment