Skip to content

Commit b81305f

Browse files
author
trinef
authored
Merge pull request #25 from DekodeInteraktiv/iss24-external-links
Add class if link url is external
2 parents e94c0c3 + aad51ae commit b81305f

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.1.5
4+
* Add class to list item if link is external
5+
36
## 1.1.4
47
* Dynamic content can list terms in a taxonomy
58
* Dynamic content can limit posts to a set category

assets/template.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
<ul class="<?php echo esc_attr( $list_classes ); ?>">
4646
<?php
4747
foreach ( $items as $item ) {
48-
printf( '<li class="%s">', esc_attr( $list_li_classes ) );
48+
$list_li_class_ext = isset( $item['external'] ) && true === $item['external'] ? ' hogan-linklist-item-external' : '';
49+
50+
printf( '<li class="%1$s%2$s">', esc_attr( $list_li_classes ), esc_attr( $list_li_class_ext ) );
4951
printf( '<a%s>',
5052
hogan_attributes( [
5153
'href' => $item['href'],

class-linklist.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,10 @@ public function get_list_items( array $list ) : array {
273273
$menu = $list['predefined_list'];
274274
foreach ( wp_get_nav_menu_items( $menu ) as $link ) {
275275
$items[] = [
276-
'href' => $link->url,
277-
'target' => $link->target,
278-
'title' => $link->title,
276+
'href' => $link->url,
277+
'target' => $link->target,
278+
'title' => $link->title,
279+
'external' => strpos( $link->url, home_url() ) === false,
279280
];
280281
}
281282
break;
@@ -287,9 +288,10 @@ public function get_list_items( array $list ) : array {
287288
}
288289

289290
$items[] = [
290-
'href' => $item['link']['url'],
291-
'target' => $item['link']['target'],
292-
'title' => hogan_get_link_title( $item['link'] ),
291+
'href' => $item['link']['url'],
292+
'target' => $item['link']['target'],
293+
'title' => hogan_get_link_title( $item['link'] ),
294+
'external' => strpos( $item['link']['url'], home_url() ) === false,
293295
];
294296
}
295297
break;

hogan-linklist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/dekodeinteraktiv/hogan-linklist
55
* GitHub Plugin URI: https://github.com/dekodeinteraktiv/hogan-linklist
66
* Description: Link List Module for Hogan
7-
* Version: 1.1.4
7+
* Version: 1.1.5
88
* Author: Dekode
99
* Author URI: https://dekode.no
1010
* License: GPL-3.0-or-later

0 commit comments

Comments
 (0)