Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressでコピーしたテキストに続きを読むリンクを追加する方法

人気サイト(eHowなど)が、サイトからコピーしたテキストに「続きを読む」リンクを添付していることにお気づきだろうか。これは新規ユーザーを獲得するための素晴らしい方法です。サイトのテキストをコピー&ペーストしてメールに送る人はよくいる。将来のために情報を保存するために使う人もいれば、友人や家族、同僚と共有するためだけに使う人もいる。この投稿では、WordPressブログからコピーしたテキストに “続きを読む “リンクを簡単に追加する方法をご紹介します。

カテゴリー:この投稿にあるものをコピー&ペーストして、メールやメモ帳に貼り付けてみてください。

まず最初に、以下のコードをテーマのfunctions.phpファイルまたはサイト固有のプラグインにコピーしてください:

[cbk1]

これで、誰かがあなたのサイトを訪れ、あなたのコンテンツをコピーしようとすると、続きを読むリンクが一緒に表示されるようになります。コピーライトのテキストを変更し、あなたのサイトのタイトルを追加することを忘れないでください。

編集:当初はウィンドウのURLを取得していましたが、ユーザーの一人からURLが不格好になるとの指摘を受けました。そこで、個別投稿ページにのみ表示し、wp_shortlinkを使用するようにコードを更新しました。つまり、yoursite.com/?p=23のようになります。wpbeg.inのようにカスタマイザーショートリンクを使用している場合は、ブランドショートリンクが表示されます。

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

アバター

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

60件のコメント返信を残す

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Bee

    Hi,
    this code does not seem to work, neither on your website here nor on my website using your snippet (WP 6.2). Could you please check this? Thank you.

    • WPBeginner Support

      The code is still working for us, we would recommend trying to disable any plugins and/or using an incognito browser to prevent addons to see if one may be causing a conflict.

      管理者

  3. Edward Elric

    Is this still working in 2020 with latest Wordpress?

    • WPBeginner Support

      Unless we hear otherwise, the code should still work when added to your site.

      管理者

  4. Junuk

    Hi, Thank you for your good information!

    I applied the code you have told me with BItly plugin to my website, but it works sometimes and doesn’t work sometimes.

    Does this code have relation with Cache plug-in? Can you tell me where in my website I should take a look?

  5. Pierre

    Hi,

    Thanks, it’s work fine on article on 2019, but it’s possible to make it work on custom post type?

    I have Eventon and WP News and Scrolling Widgets.

    • WPBeginner Support

      You would need to modify the is_single to is_singular and add the name of your custom post type

      管理者

  6. Will

    Do you have any advice on how to add Google tracking parameters to the end of each URL? Considering you’re already using ?p= for the post name at the end.

  7. Akash

    Is there an easy way to make it work on categories, too?

  8. Jasmine

    Thanks for this, it works great for posts but when text is copied from events it doesn’t pull the URL of the page through – any advice? Thanks.

    • Michele

      This is awesome. Thanks. When it says class – entry content, that meant it didn’t work for about 90% of the text on my site because my text didn’t use that class name. So if anyone else encounters this problem, you can change “entry content” to “body”. That’s what I did.
      var body_element = document.getElementsByTagName(‘body’)[0]; (line 13)
      Now it works everywhere.

  9. Meenu

    How can I limit the content?

  10. Dave

    Thank you very much, all the text formatting were changed and pasted as a single line. But I need the text formatting as it is. So please help me in getting this.

    • Ark

      Same here, all line breaks are missing after the paste.

  11. Jens | Sir Apfelot

    Damn… I am stupid… I added it to the themes custom JS… thats not working. :-)

  12. Jens | Sir Apfelot

    Just added the script into my wordpress blog, but I dont get an appendix at the clipbiards end…

    Any ideas? I am not sure, if its because I am working on a mac… but I guess the javascript should work on Firefox on a mac too… :-(

  13. Yash Jhade

    While pasting it to blogger following error comes
    Error parsing XML, line 2237, column 96: The value of attribute “href” associated with an element type “a” must not contain the ‘<' character.
    Any Solutions ?
    Thanks.

  14. matt

    this feature makes copying and pasting more frustrating. For instance, if I copy and paste a headline for editing Wikipedia it can mess up formatting if I’m not careful and requires extra work.

  15. Anon

    As a user, I can’t stand this. Please don’t add this.

  16. Alan

    Anybody knows how to keep the format?

    When using this plugin all the spaces, line break and format goes away.

  17. Philip-Daniel Kleudgen

    Works like a charm! The only thing i wish it would do is limit the amount of copied text to for example 150 words or something like that.

  18. Salud Casera

    No longer works for me.

    It was working before though but I think it has more to do with the theme rather than the WP version

  19. Alyson

    Unfortunately, the code does not work with WP 3.8

    I have tested it on a fresh install. Please feel free to confirm this. Do you have any plans to update the code to make it function?

    • WPBeginner Support

      We just tested it with a fresh WP 3.8 install and it is working perfectly on our side.

      管理者

      • Erik

        I can’t get this to work either actually.

    • Roselle

      Hello,

      At first, I could not get this to work. But upon close examination, I figured out the culprit:

      On the 8th line of the code, you’ll see this:
      document.getElementsByClassName(‘entry-content’)[0], true))

      This is the line that tells the code, “hey, if anyone copies text from text with this class name, then put a read more link”

      All you need to do is use Firebug to figure out what class name your post content is under.

      I have a child theme that I’ve edited over and over again, so mine wasn’t the default, “entry-content”. I suspect your class name is different from that also.

      Good luck,
      Roselle

      • Salud Casera

        What are the steps to follow with Firebug to figure out the post class name?

  20. Gabriel

    Hello,

    Many thanks for this great article, but I have a problem. I would like to get the permalink and not the shorthen link. Anyone can tell me how can I do that?

    Cheers

  21. Gretchen Louise

    Is there an easy way to make it work on single pages, too?

      • Gretchen Louise

        Thank you! That works, except it doesn’t grab a link for pages…just posts.

        • Editorial Staff

          That’s weird. get_the_id should work for both pages and posts.

        • Gretchen Louise

          I have it workign on KindredGrace . com but it doesn’t grab the id for pages, just posts.

        • Editorial Staff

          Try adding the global variable. Because get_the_id works for posts and pages are also a “post type”

      • Gretchen Louise

        I tried it like this and still no luck on grabbing the shortlink for pages:

        // Add copyright text
        function add_copyright_text() {
        global $post; { ?>

      • Brian York

        This change worked for me. However do double check that you have your content under ‘entry-content’ otherwise change that (F12 in Chrome). Thanks WPBeginner!!

      • Brian York

        Actually this doesn’t quite work right. It doesn’t work in IE at all and no matter what I do its not copying the HTML part but always converting it to plain text thus would never make a link.

        • alan

          I have the same problem, it removes all the format, does anybody knows a fix to this?

  22. Collin Weeks

    Love your website! Thanks for taking the time to share with everyone.

  23. Mairaj Pirzada

    Nice, Post but I always don’t like Codings, it confuses me!

  24. Helder

    It´s not working, even with wpbeginner.com content

    • Editorial Staff

      We took the code off our website. Some users complained that they found it annoying.

      管理者

  25. Rafiul Islam

    WOW… Many Many Thanks for share it,, I am suffering for this …
    Thanks again.

  26. Lorenzo Solís

    Does someone know how to do not show the “Read More Link” when the post title is copied?

    Thanks!

    • Editorial Staff

      Yes it is possible. Change the selector tag from body to a div ID or what not. I have put the request in. Our developers will let me know, so I can update the article.

      管理者

      • Lorenzo Solís

        Thanks. I’ve just tried with var div = document.getElementById(‘copyright’); in the line number 6 and adding de id=”copyright” to the div content, but I get the same result as with your code. Sorry, I am not a programmer.

  27. Paul

    Thanks, this looks interesting I’ll be trying it out soon

  28. Lisa

    It also worked fine in a new email composed from Outlook, so I’d say it’s a Gmail issue. Thanks!

  29. Lisa

    Interesting and useful; however, I was surprised that the copy test did not work (for me at least) when composing an email in Gmail — nothing showed after pasting the copied text, and the body text area in the compose email window just froze. Testing a copied bit in Notepad worked just fine, so I don’t know what the issue might be with Gmail.

    Thanks for the tip!

  30. Albert Albs

    That is good option Syed. Thanks for sharing. But if we can able to print short URL of the post means, that is even better for website owners.

    Currently it is printing long URL. If I came here by Feedburner newsletter subscription, the UTM tracking url also coming.

    Hope you understand. Is it possible?

    • Editorial Staff

      Ah hah. Good suggestion. Writing it down in the list of to-do things for WPBeginner.

      Edit: Just updated the code :)

      管理者

      • Albert Albs

        That is fast and smart.

        One Question: Why you removed Author URL in the comment form? Always, I’m seeing, many of the WordPress powered blogs will give credit to the comment author at URL field with NoFollow attribute.

        Is there any specific reason for removing Author URI field? Or are there any experiments for Penguin update?

        Between, I’m not getting any comment notification, even after selecting the “Notify me of followup comments via e-mail” option.

  31. Gabe Diaz

    Wow, now this is a great tip! Makes it easy to quote and show attribution as well as drops a link for those who skim and steal content. Very cool!

  32. Emily Sandford

    Thanks so much for this. It was so easy to do, and something I wondered about for quite some time. Appreciate it!

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。