WordPress.org

Ready to get started?Download WordPress

Forums

Page Links To
Link STILL doesn't open in new window (24 posts)

  1. MissDeja
    Member
    Posted 2 years ago #

    I know this has been mentioned a number of times, but I'll bring it up again since those posts are closed to further discussion.

    Even though the "open in new window" box is checked, it's not doing so.

    If there is no support for this plugin anymore, and no fix for this problem, can anyone recommend a different plugin that does basically the same thing as this one is supposed to do? I have a few WP sites that need external link menu items (which open in a new window), and I haven't been able to track down anything else.

    http://wordpress.org/extend/plugins/page-links-to/

  2. deborah64554
    Member
    Posted 2 years ago #

    I am having the same issue. "Open in new window" is checked, but the correct link opens in the same window. I can not make heads or tails of the javascript... Help?

  3. deborah64554
    Member
    Posted 2 years ago #

    I should have added that I just did the most recent WordPress update on a fresh install, using a copy of the twenty-eleven theme.

    When I look at the plugin php file, the last section seems to be telling it to add a javascript to the html head within an if-else statement about targets. However the javascript is not there when I look at the page source.

    If I remove the if-else part of the statement so that it just adds no matter what, it shows up, but the external links still open in the same window and not a "_blank" target.

  4. deborah64554
    Member
    Posted 2 years ago #

    This seems to have broken after the new WordPress release was installed earlier this week. I checked another thread in this forum and the "extra space" solution did not work (the newest version of the plugin does not have an extra space).

    No help?

  5. deborah64554
    Member
    Posted 2 years ago #

    I think I found part of the issue - the string replace for '<a href="' can not replace because the actual string begins with '<a title="(title' before the href is defined. So the string to replace does not exist.

  6. deborah64554
    Member
    Posted 2 years ago #

    However, modifying the string replace script to just replace from href did not solve the issue.

  7. deborah64554
    Member
    Posted 2 years ago #

    Ok, for me the issue is that there is a conflict with the plugin I am using to display the posts. I could not test the posts without the plugin because without the plugin it was hard to display the correct posts on the page.

    The plugin is "List category posts". This plugin writes the page-links-to url correctly, but does not take target into account.

    I'm experimenting with modifications to list-category-posts.

  8. deborah64554
    Member
    Posted 2 years ago #

    Ok, for users who also have list-category-posts plugin and are seeing page-links-to opening in the same window, here's a brief summary of the cause and specific details on how to get things working so that the new window opens.

    Cause: Page-Links-To sets the post url in the database, but uses a script to re-write the link tag if the "open in a new window" feature is checked for the post. List-Category-Posts gets the url from the database, but uses its OWN script to write the link tag - it never sees and can not implement the Page-Links-To script, which contains the "new window if box is checked" logic.

    This means that in order to get List-Category-Posts to open posts in a new window, you have to create new functions that write the link tag with "target='_blank'" in it, create a List-Category-Posts template for it that calls those functions, and use that template when you want a new window. This method will work for a list of links that must open in a new window and for a list that does not, but you will not be able to have a mixed list (unless, that is, you create a brilliant solution on your own). I hope also that experienced php coders will forgive anything I am recommending here that may be redundant.

    To get List-Category-Posts to make a list of links that open in a new window:

    In CatList.php:

    • Find the function "get_category_link"
    • Copy and paste this function below the original
    • Re-name it to "get_category_link_new_win"
    • Change the line return '<a href="' . $cat_link . '" title="' . $cat_title . '">' . to return '<a href="' . $cat_link . '" title="' . $cat_title . '" target="_blank">' .
    • Find the function "get_the_post_thumbnail"
    • Copy and paste this function below the original
    • Re-name it to "get_the_post_thumbnail_new_win"
    • Change the line $lcp_thumbnail = '<a href="' . get_permalink($single->ID).'">'; to $lcp_thumbnail = '<a href="' . get_permalink($single->ID).'" target="_blank">';

    In CatListDisplayer.php:

    • find the function "get_thumbnail"
    • Copy and paste it below itself
    • Re-name it to "get_thumbnail_new_win"
    • Change the line $info = $this->catlist->get_thumbnail($single, $lcp_thumb_class); to $info = $this->catlist->get_thumbnail_new_win($single, $lcp_thumb_class);
    • find the function "get_post_title"
    • Copy and paste it below itself
    • Change the line $info = '<a href="' . get_permalink($single->ID) . '">' . to $info = '<a href="' . get_permalink($single->ID) . '" target="_blank">' .

    Open list-category-posts/templates/default.php and save it to (your template folder)/list-category-posts/new-window.php

    • Please note the new file must be in a NEW list-category-posts folder in YOUR template folder, not the plugin folder!
    • Change $lcp_display_output .= $this->get_thumbnail_mm($single); to $lcp_display_output .= $this->get_thumbnail_new_win($single);
    • Change $lcp_display_output .= $this->get_post_title_mm($single); to $lcp_display_output .= $this->get_post_title_mm($single);
    • Save that sucker.

    Now in WordPress, in your shortcode to create a list that uses the new-window template, put template=new-window before the ending bracket.

    Behold! If I have made no critical typos and you have copied and pasted with diligent accuracy, you should now have a list of posts that open in a new window.

    Good luck! :)

  9. Dale Buchanan
    Member
    Posted 2 years ago #

    I wish I had the experience to follow this last post, but I don't and like missdeja said, the open in new window box is checked but it's not working and I'm using 3.4.1

    I'm confused

  10. MissDeja
    Member
    Posted 2 years ago #

    Dale, I also, unfortunately, don't have the expertise to follow deborah64554, but I did find a solution.

    The plugin, "Open External Links in a New Window" (http://wordpress.org/extend/plugins/open-external-links-in-a-new-window/), overrides the problem. Don't disable "Link Opens To", but use them simultaneously!

  11. Mark Jaquith
    WordPress Lead Dev
    Plugin Author

    Posted 2 years ago #

    The plugin only modifies links that appear (a) In a WordPress nav menu (b) in an oldschool wp_list_pages() output, or (c) is a post in the main "loop" query.

    If you're using custom functions to output the links some other way, it won't work.

    I'm considering ways to lift these restrictions, without introducing a lot of overhead.

  12. rajaman
    Member
    Posted 1 year ago #

    I'm having the same problem. Even though the "open in new window" box is checked, it's not doing so.

    Does anyone have solution to this?

  13. trickynek
    Member
    Posted 1 year ago #

    @deborah64554 - Do you have a general solution for those who are not also using the List-Category-Posts plugin? Yours appears to be the only potential solution I have found, its clearly a problem for anyone thats using the plugin in general

  14. ratputin
    Member
    Posted 1 year ago #

    Same issue here. Up-to-date plugin/WP install. Is there a fix or work-around?

  15. patmav
    Member
    Posted 1 year ago #

    What MissDeja said above works great!!! Not sure why or how (ha,ha,ha!!) but it works!!!

  16. pwdoherty
    Member
    Posted 1 year ago #

    I added the "Open External Links in a New Window" plugin and am still having problems.

    My site is http://www.pwdoherty.com

    I am clicking from the slider menu to my expernal page http://www.phonatomy.com.

    A new browser window opens with phonatomy.com but the original browser window - also redirects to phonatomy.com.

    What am I doing wrong? A bit of a novice here....

  17. Amy Elizabeth
    Member
    Posted 1 year ago #

    I read these comments and I STILL cannot get it to work. I added the open external link in new window plugin and still no luck. Any more suggestions???

  18. jumust
    Member
    Posted 1 year ago #

    I have left this plugin for a couple of years because it was not useful since the OPEN LINK IN A NEW TAB was not working.

    I have just installed it again and I hoped to find this bug fixed but it's still not working.

    Mark Jaquith, do you have any idea when you will fix this main feature of your plugin?

    If it's going to be a late fix in the years, folk do you suggest any other plugin that does similar things?

    Thanks

  19. JayMarvalous
    Member
    Posted 1 year ago #

    Thanks MissDeja! The "Open external links in a new window" plugin worked like a charm>

  20. Jayesh Patel
    Member
    Posted 1 year ago #

    Fixed this issue

    page-links-to.php (line no 212)

    function template_redirect() {
    if ( !is_single() && !is_page() )
    return;
    global $wp_query;
    $link = get_post_meta( $wp_query->post->ID, '_links_to', true );
    if ( !$link )
    return;
    wp_redirect( $link, 301 );
    exit;
    }

    Replace with below code

    function template_redirect() {
    //if ( !is_single() && !is_page() )
    // return;
    global $wp_query;
    $link = get_post_meta( $wp_query->post->ID, '_links_to', true );
    if ( !$link )
    return;
    wp_redirect( $link, 301 );
    exit;
    }

    It is working fine :)

  21. dotmandesign
    Member
    Posted 1 year ago #

    ANother Hoorah! for MissDeja's contribution. This has been the only way I've been able to get it to work as well. Crazy that it was this much effort to get something to do what you'd think it should do already!

  22. ratputin
    Member
    Posted 1 year ago #

    @Jayesh Patel

    I tried your solution and it resulted in the entire website automatically redirecting to the external link onLoad.

  23. Jayesh Patel
    Member
    Posted 1 year ago #

    @ratputin

    Please use below code

    <?php
    $newtarget = get_post_meta( $post->ID, '_links_to', true);
    if ($newtarget){$target_link = 'target="_blank"';} else {$target_link = '';}
    ?>

    < a href=" #link-here " > ><?php the_title();?>< / a >

    It is working fine :)

  24. ratputin
    Member
    Posted 1 year ago #

    @Jayesh Patel

    Sorry, but I do not understand the implementation. Should I replace the code starting at line 212 in page-links-to.php with:

    <?php
    $newtarget = get_post_meta( $post->ID, '_links_to', true);
    if ($newtarget){$target_link = 'target="_blank"';} else {$target_link = '';}
    ?>
    
    < a href=" #link-here " > ><?php the_title();?>< / a >

Topic Closed

This topic has been closed to new replies.