[Resolved] Archive page – make link open in new post

Home Forums Support [Resolved] Archive page – make link open in new post

Home Forums Support Archive page – make link open in new post

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1284989
    Janani

    Hi

    In my archive page, how do I make the link to the post open in a new page?

    Warm regards,

    #1285012
    Leo
    Staff
    Customer Support
    #1286596
    Janani

    Dear Leo

    Thanks. Apologies, but I am a beginner, so wanted to check with you where I would add this code. This does not seem to be a normal CSS code.

    #1287181
    David
    Staff
    Customer Support

    Hi there,

    that code is Javascript.
    To add that to your site you would:

    1. Create a new hook element.
    https://docs.generatepress.com/article/hooks-element-overview/
    2. Add the code to the hook content.
    3. Select the WP_Footer hook
    4. Set the Display Rules for the pages where you need this could to be fired.

    #1297817
    Janani

    Dear David

    Thanks I tried it but it did not work. Pls let me know what I did wrong.

    I chose wp_footer, ticked on execute shortcodes, execute PHP, priority 10.

    Below is this is the script I used:
    <script type=”text/javascript”>
    //<![CDATA[
    jQuery(document).ready(function($) {
    $(‘h2.entry-title a’).each(function() {
    var a = new RegExp(‘/’ + window.location.host + ‘/’);
    if(!a.test(this.href)) {
    $(this).click(function(event) {
    event.preventDefault();
    event.stopPropagation();
    window.open(this.href, ‘_blank’);
    });
    }
    });
    });
    //]]>
    </script>

    #1298274
    Leo
    Staff
    Customer Support

    You don’t need to check to execute shortcodes and execute PHP but I do think you need to load jQuery like this:
    https://generatepress.com/forums/topic/shortcode-does-not-show-in-front-end/#post-475755

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1301364
    Janani

    Dear Leo

    Do you suggest I install a plugin for this purpose? Is there no way I can do this without a plugin?

    Warm regards,

    #1301907
    David
    Staff
    Customer Support

    Hi there,

    try this Javascript instead:

    <script>
    jQuery(document).ready(function($){
        $('.entry-title a').attr('target', '_blank');
    }); 
    </script>
    #1302868
    Janani

    Dear David

    This is perfect. It worked! Thank you very much.

    #1303113
    David
    Staff
    Customer Support

    You’re welcome

    #1351184
    Janani

    Hi David,

    This issue was resolved, but recently I noticed that the post does not open on a new page. Could there be any reason for this?

    Warm regards,

    #1351371
    David
    Staff
    Customer Support

    I cannot see the code added to your site.
    Where did you add it? If it is using a Hook – make sure it is still published and the display rules are correct

    #1351431
    Janani

    Thanks David. I guess the hook got modified accidentally. This issue is resolved.

    #1351774
    David
    Staff
    Customer Support

    Glad to hear that

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