Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1291604

    Hi, i have a problem with that URL

    When i use in the Blog the “link post type” which are external links, they should be straight opened in a new tab. So if you click on the title or read more button, the article should be opened and not the post itself. But only for post types “links”.

    Can you help me?

    I have this code here, but it’s only working for the grid layout and not for the one i use.

    // OPEN BLOG POST TYPE “LINK” IN NEW TAB

    add_action(‘wp_footer’, ‘ava_custom_script’);
    function ava_custom_script(){
    ?>
    <script type=”text/javascript”>
    (function($) {
    function a() {
    $(‘.slide-entry-title a, .slide-image’).each( function() {
    var site = document.location.host,
    link = $(this).attr(‘href’);

    if(link.indexOf(site) !== -1) {
    return;
    } else {
    $(this).attr(‘target’, ‘_blank’);
    }
    });
    }

    a();
    })(jQuery);
    </script>
    <?php
    }

    #1292070

    Hey ronaldalexander,

    Please try this in your functions.php file:

    function link_format_read_more_link_new_tab(){
      ?>
      <script>
      	jQuery(document).ready(function($) {;
      		$('article.format-link .read-more-link a').attr('target', '_blank');
      	});
      </script>
      <?php
    }
    add_action('wp_footer', 'link_format_read_more_link_new_tab');

    Best regards,
    Rikard

    #1292382

    Hi,

    thanks for the code. It works for the Read more link but not for the title. There is one problem, the subpage gets openen but not the final link. I dont want to open the article on the page, i want to open the final article / URL is put into the article.

    Bests

    #1292422

    Hi ronaldalexander,

    It won’t work because the permalinks point to a single post page and not to an external link.
    You most likely will need a plugin for that, please try to check this article: https://firstsiteguide.com/link-posts-pages-external-url/
    Hope it helps.

    Best regards,
    Nikko

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.