• Hi there,

    I’m using a theme where social links are predefined, however when set as “target=’_blank’” It does not work. I’ve located the source PHP code in the theme but my ability to modify it to my needs and introduce “Target=’_blank’” function are limited.

    Please help to modify this code: and introduce “target”blank function for all instances.

    Thanks, greatly appreciated.

    
    if (!$type) {
    foreach ($items_array as $item) {
    $icon = $default_icons[$item[‘type’]][‘icon’];
    $html .= ‘<i class=”‘ . esc_attr($icon) . ‘”></i>‘;
    }
    
    return $html;
    } elseif ($type == ‘square’) {
    foreach ($items_array as $item) {
    $icon = $square_icons[$item[‘type’]][‘icon’];
    $html .= ‘<i class=”‘ . esc_attr($icon) . ‘”></i>‘;
    }
    
    return $html;
    } elseif ($type == ‘with-title’) {
    foreach ($items_array as $item) {
    $icon = $default_icons[$item[‘type’]][‘icon’];
    $title = $default_icons[$item[‘type’]][‘title’];
    $html .= ‘<i class=”‘ . esc_attr($icon) . ‘”></i><span>’ . strip_tags($title) . ‘</span>‘;
    }
    
    • This topic was modified 4 years, 9 months ago by Marius L. J.. Reason: Fixed code formatting
Viewing 10 replies - 1 through 10 (of 10 total)
  • There’s nothing in that code that indicates anywhere that a ‘target=”_blank”‘ could go (and actually work). You ned to find out where the <a> tags are being defined, and that’s where you’d look to add it in.

    • This reply was modified 4 years, 9 months ago by Marius L. J.. Reason: Fix formatting
    Thread Starter laura-work-in-progress

    (@laurafallofman)

    Thanks @catacaustic,

    This is the actual header code, I tried to add this command here but no luck either:

    
    if(pt_get_theme_setting('header_social_links') == 'true' && $social_links = pt_build_social_links()) {
      $header_social_links_html = '<div class="social-links">'.$social_links.'</div>';
    }
    

    Thanks for your time, much appreciated. I’ve been at this for hours (not a pro in coding as you can tell), but no luck

    • This reply was modified 4 years, 9 months ago by Marius L. J.. Reason: Fixed code block
    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You should not use target blank links by default, this is anti-user and an anti-pattern.

    Thread Starter laura-work-in-progress

    (@laurafallofman)

    @otto42 The requirement here is to open social media links in new window, therefore not leaving my website – so in this scenario it is required.

    Are there better ways to do it? happy to take on board some advice ??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    @laurafallofman Correct. That is an anti-pattern. You want to not do that.

    Users have the ability to open links in new windows when they want to do so, by middle clicking, or ctrl clicking, or whatever. You do not want users to do that when they are not expecting to do so.

    Opening a new window or tab is something that should be only used for out-of-band processes. Like, if you need to open a window to receive login credentials, which you then close the window again after getting them. That is the purpose of it.

    If you’re using it to “keep them on your site” then you’re doing it wrong and using it for the wrong purposes. This leads to less user engagement with your site, and makes it more inaccessible and wrong. Basically users hate it, and hate you for doing it. This sort of thing creates bad websites.

    Don’t make bad sites. Make good ones.

    Thread Starter laura-work-in-progress

    (@laurafallofman)

    @otto42

    in this scenario i do need it for my header social links since it takes you to a twitter.com or an instagram.com page. So here the impaction is that it leaves my site regardless. So thanks for the advice it won’t be relevant this time around ??

    This is the actual header code, I tried to add this command here but no luck either

    Well, no, you won’t.

    As I said before, you need to find where the tags are being generated. There’s no a tag in that code, so that’s not the place and you need to look further into it.

    Thread Starter laura-work-in-progress

    (@laurafallofman)

    hi @catacaustic

    Thanks for your response, I’ve found the location of each individual social link and wondering if the array could be wrapped into a link itself with target blank?

    here’s the code:

    if (!function_exists(‘pt_build_social_links’)) {
    function pt_build_social_links($type = false, $items = false) {
    $html = ”;
    $default_icons = array(
    ‘500px’ => array(
    ‘icon’ => ‘fab fa-500px’,
    ‘title’ => esc_html__(‘500px’, ‘unta’),
    ),
    ‘amazon’ => array(
    ‘icon’ => ‘fab fa-amazon’,
    ‘title’ => esc_html__(‘Amazon’, ‘unta’),
    ),
    ‘app-store’ => array(
    ‘icon’ => ‘fab fa-app-store’,
    ‘title’ => esc_html__(‘App Store’, ‘unta’),
    ),
    ‘behance’ => array(
    ‘icon’ => ‘fab fa-behance’,
    ‘title’ => esc_html__(‘Behance’, ‘unta’),
    ),

    Thread Starter laura-work-in-progress

    (@laurafallofman)

    @catacaustic

    I think I’ve located the actual code, I tried to define target “blank here, but no luck. If you’re able to advice, that would be wonderful, thanks

     if (!$type) {
            foreach ($items_array as $item) {
              $icon = $default_icons[$item['type']]['icon'];
              $html .= '<a href="' . esc_url($item['url']) . '" target=" '_blank' "><i class="' . esc_attr($icon) . '"></i></a>';
            }
    
            return $html;
          } elseif ($type == 'square') {
            foreach ($items_array as $item) {
              $icon = $square_icons[$item['type']]['icon'];
              $html .= '<a href="' . esc_url($item['url']) . '" target=" '_blank'"><i class="' . esc_attr($icon) . '"></i></a>';
            }
    
            return $html;
          } elseif ($type == 'with-title') {
            foreach ($items_array as $item) {
              $icon = $default_icons[$item['type']]['icon'];
              $title = $default_icons[$item['type']]['title'];
              $html .= '<a href="' . esc_url($item['url']) . '" target= " '_blank'"><i class="' . esc_attr($icon) . '"></i><span>' . strip_tags($title) . '</span></a>';
            }
    
            return $html;
          }

    It’s at least the right area. But you’ve added it all wrong. It should be like this:

    $html .= '<a href="' . esc_url($item['url']) . '" target="_blank"><i class="' . esc_attr($icon) . '"></i></a>';

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘add target”_blank” to PHP code’ is closed to new replies.