• 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)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Read more link to copied text not working’ is closed to new replies.