• Resolved cedam lee

    (@jakes9)


    function add_copyright_text() {
    	if (is_single()) { ?>
    
    <script type='text/javascript'>
    function addLink() {
    	if (
    window.getSelection().containsNode(
    document.getElementsByClassName('entry-content')[0], true)) {
        var body_element = document.getElementsByTagName('body')[0];
        var selection;
        selection = window.getSelection();
    	var oldselection = selection
        var pagelink = "<br /><br /> Read more at WPBeginner: <?php the_title(); ?> <a href='<?php echo wp_get_shortlink(get_the_ID()); ?>'><?php echo wp_get_shortlink(get_the_ID()); ?></a>"; //Change this if you like
        var copy_text = selection + pagelink;
        var new_div = document.createElement('div');
    	new_div.style.left='-99999px';
    	new_div.style.position='absolute';
    
        body_element.appendChild(new_div );
        new_div.innerHTML = copy_text ;
        selection.selectAllChildren(new_div );
        window.setTimeout(function() {
            body_element.removeChild(new_div );
        },0);
    }
    }
    
    document.oncopy = addLink;
    </script>
    
    <?php
    }
    }
    
    add_action( 'wp_head', 'add_copyright_text');

    https://www.wpbeginner.com/wp-tutorials/how-to-add-a-read-more-link-to-copied-text-in-wordpress/

    I added this code at the functions.php file it gave me error then i enclosed it within <?php ?> then it didn’t but after that I tested it, it didn’t work.
    But on another website which has a different theme it worked there

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael

    (@mh-themes)

    Hi Cedam,

    thanks for using MH Purity lite.

    In general it’s not recommended to copy & paste code which you’ve found on the internet to themes which you’re using on a live site. Not only is there no guarantee that the code always will work as expected (with all themes and plugins) but there also is a risk of security issues (the article you’re referring to is from 2012).

    However, we can’t debug your code here, but in general you could analyze the code as it’s possible that it needs to be modified to work as expected. As an alternative you also could check if there are any up-to-date plugins that can do what you have in mind: https://www.ads-software.com/plugins/

    meenu rengaraj

    (@meenu-rengaraj)

    How can I limit the content??

    Michael

    (@mh-themes)

    @meenu rengaraj: Please open your own forum thread and clarify your question: https://www.ads-software.com/support/theme/mh-purity-lite#postform

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Read more link to copied text not working’ is closed to new replies.