Home Forums Pro Themes Photomania Pro Open all external links in new window

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #37153
    EZiser
    Participant

    Hi WEN,

    I’m having trouble finding an answer for this – all results seem to be theme specific.

    What snippet of code can I add to PhotoMania Pro so all external links open in a new tab? I’d like to do this without adding another plugin.

    Thanks!

    #37160
    wensolutions
    Keymaster

    Hello @eziser,

    If you want all of your external link to open in a new tab you have to include js code .

    For this you can go through the child theme approach or add an external plugin.

    Below is the link to one of the plugin :

    https://wordpress.org/plugins/custom-css-js/

    Then include below given js code .

    jQuery(document).ready(function($){
      
    	$("a[href^=http]").each(function(){
              if(this.href.indexOf(location.hostname) == -1) {
                 $(this).attr({
                    target: "_blank",
                    title: "Opens in a new window"
                 });
              }
           })  
      
    });

    Note: We cannot assure 100% compatibility of the plugin we have recommend to the theme as we have not tested the compatibility of the plugin to the theme .

    Hope this helps.

    Best Regards!!

    #37228
    EZiser
    Participant

    Hi WEN,

    Thanks for your prompt response. Where do I add the jc code in the child theme?

    To reiterate: this must be done WITHOUT a plugin; particularly one that hasn’t been tested.

    #37244
    wensolutions
    Keymaster

    Hello @eziser,

    To include the js code in the child theme you have to enqueue the js script in your functions.php file .

    Your child theme functions.php should contain the below given code:

    <?php
    
    add_action( 'wp_enqueue_scripts', 'photomania_pro_child_style' );
      function photomania_pro_child_style() {
    	wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    	wp_enqueue_style( 'child-style',get_stylesheet_directory_uri() . '/style.css',array('parent-style'));
      wp_enqueue_script( 'photomania-child-custom-js', get_stylesheet_directory_uri() . '/custom.js', array('jquery'), '' , true );
    }

    Now create the custom.js file in your child theme and add below given code in the file .

    jQuery(document).ready(function($){
      
    	$("a[href^=http]").each(function(){
              if(this.href.indexOf(location.hostname) == -1) {
                 $(this).attr({
                    target: "_blank",
                    title: "Opens in a new window"
                 });
              }
           })  
      
    });

    Hope this clears up the confusion.

    Best regards!!

    #37246
    EZiser
    Participant

    Hi WEN,

    You stated, “you have to enqueue the js script in your functions.php file .” I don’t know what this means. Could you clarify?

    I have a functions.php file in my child theme. I added your second script; it did not work.

    Let me know if I’m missing something. I’m versed in html, but novice in js. I’ll require step by step instruction.

    You may email me directly if easier.

    Thanks!

    #37247
    wensolutions
    Keymaster

    Hello @eziser,

    Please follow below given Steps.

    – First of all in your child theme functions.php file include below given code .

      add_action( 'wp_enqueue_scripts', 'photomania_pro_child_style' );
      function photomania_pro_child_style() {
    	
      wp_enqueue_script( 'photomania-child-custom-js', get_stylesheet_directory_uri() . '/custom.js', array('jquery'), '' , true );
    }

    – Then create custom.js file in your child theme .
    – Now add below given code in your child themes custom.js file .

    jQuery(document).ready(function($){
      
    	$("a[href^=http]").each(function(){
              if(this.href.indexOf(location.hostname) == -1) {
                 $(this).attr({
                    target: "_blank",
                    title: "Opens in a new window"
                 });
              }
           })  
      
    });

    Hope this helps.

    If you have any confusion further, please let us know.

    Best regards!!

    #37298
    EZiser
    Participant

    “Then create custom.js file in your child theme .”

    How do I do this?

    #37311
    wensolutions
    Keymaster

    Hello @eziser,

    Steps to follow:

    -First of all create the text document naming custom.txt and paste the js code with the help of text editor like notepad inside your child theme folder.

    -Then rename the text file as custom.js and save it.

    If you are finding it difficult to create the file replace above given code with code given below in your child themes functions.php file .

    
    function photomania_pro_child_custom_js() { ?>
    
    <script type="text/javascript">
    jQuery(document).ready(function($){
      
    	$("a[href^=http]").each(function(){
              if(this.href.indexOf(location.hostname) == -1) {
                 $(this).attr({
                    target: "_blank",
                    title: "Opens in a new window"
                 });
              }
           })  
      
    });
    
    </script>
    <?php
    }
    
    add_action( 'wp_footer', 'photomania_pro_child_custom_js' );

    Hope this clears the confusion.

    Best regards!!

    #37326
    EZiser
    Participant

    Hi WEN,

    Sorry for the confusion – but where in the WordPress > Editor > Child theme is an option to “create file”. I can create it on my desktop, but there’s also nowhere to “upload file”.

    I can provide you a support login if that would be easier. But if we continue here, I’ll need a step by step guide on how to accomplish this.

    Thank you 🙂
    Liz

    #37331
    EZiser
    Participant

    Secondly, I added the first code to the function php. And it just inserted it as plain text atop every page.

    I’m very confused – what can we do to streamline this process?

    #37344
    wensolutions
    Keymaster

    Hello @eziser,

    Please check the mail for your follow up reply.

    And if you have any theme related queries and need any help further feel free to post them .

    Best Regards!!

    #37349
    EZiser
    Participant

    Great, thanks! We’ll continue the conversation there.

    You’ve been a wonderful help. 🙂

    #117925
    stiver1
    Participant

    Hello

    I want the same way

    1 – Put automatic external link
    2 – I also want to apply them to internal links

    Possible way to my site because I tried it my site link
    https://www.kora.news/

    It did not work
    Please help

    #118064
    wensolutions
    Keymaster

    Hello,

    The feature you are requesting is not possible.

    Regarding your query to open external links, you can refer to the above conversation and add the code.

    If the issue persists, let us know.

    Thank you.

    #118065
    stiver1
    Participant

    I added the code and it didn’t work

    Possible, what is the function of the code? Can a photo explain if my friend can

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