{"id":549,"date":"2020-10-03T11:36:01","date_gmt":"2020-10-03T11:36:01","guid":{"rendered":"https:\/\/stockpack.co\/blog\/?p=549"},"modified":"2023-09-16T05:44:12","modified_gmt":"2023-09-16T05:44:12","slug":"how-to-provide-image-credit-in-wordpress","status":"publish","type":"post","link":"https:\/\/stockpack.co\/blog\/how-to-provide-image-credit-in-wordpress\/","title":{"rendered":"How to provide image credit in WordPress"},"content":{"rendered":"\n<p>Depending on the source of the images you are using, you might need to provide credit when using them. Or you just might want to do it, to appreciate the work of the author. Either way, you&#8217;ve come to the right place. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Based on the suggestion of <a href=\"https:\/\/motivecontent.com\/\">Eric Weston<\/a>, and inspired by the article at <a href=\"https:\/\/www.tipsandtricks-hq.com\/cite-the-source-for-images-attached-to-your-wordpress-posts-8580\">Tips and Tricks HQ<\/a>, the StockPack plugin was adapted to allow citations for all images, not only the images downloaded via our plugin. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enabling the image credit fields in WordPress<\/h2>\n\n\n\n<p>Enabling support for image credit fields is straightforward. First, you need to install the <a href=\"https:\/\/wordpress.org\/plugins\/stockpack\/\">StockPack<\/a> plugin from the WordPress repository and activate it. <\/p>\n\n\n\n<p>Then you need to go to the settings page, to the Advanced tab, and enable the caption settings as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"201\" src=\"https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/enable-image-caption-fields-1024x201.png\" alt=\"\" class=\"wp-image-552\" srcset=\"https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/enable-image-caption-fields-1024x201.png 1024w, https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/enable-image-caption-fields-300x59.png 300w, https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/enable-image-caption-fields-768x151.png 768w, https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/enable-image-caption-fields.png 1224w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Enable caption settings<\/figcaption><\/figure>\n\n\n\n<p>That&#8217;s it, now you will see new fields when editing an image from the media library. The featured image caption is optional, and it <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Supported image credit fields<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"281\" height=\"716\" src=\"https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/supported-image-credit-fields.png\" alt=\"\" class=\"wp-image-551\" srcset=\"https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/supported-image-credit-fields.png 281w, https:\/\/stockpack.co\/blog\/wp-content\/uploads\/2020\/10\/supported-image-credit-fields-118x300.png 118w\" sizes=\"auto, (max-width: 281px) 100vw, 281px\" \/><figcaption>Supported image credit fields<\/figcaption><\/figure><\/div>\n\n\n\n<p>You will be able to provide image credit to all the images in the Media Library including featured images. The credit supports the following fields:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Author Name<\/li><li>Author URL<\/li><li>Source Name<\/li><li>Source URL<\/li><li>License Name<\/li><li>License URL<\/li><li>Modifications<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Autocomplete support for standard licenses<\/h2>\n\n\n\n<p>Some licenses are automatically completed for you. If you have one that you use often, please <a href=\"https:\/\/stockpack.co\/contact\">reach out<\/a> so we can add it to the list. Here&#8217;s the current list of licenses that we autocomplete:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>ccby<\/strong> =&gt; <a href=\"https:\/\/creativecommons.org\/licenses\/by\/4.0\/\">CC BY 4.0<\/a><\/li><li><strong>cc0<\/strong> =&gt; <a href=\"https:\/\/creativecommons.org\/share-your-work\/public-domain\/cc0\/\">CC0<\/a><\/li><li><strong>public<\/strong> =&gt; <a href=\"https:\/\/creativecommons.org\/share-your-work\/public-domain\/\">Public Domain<\/a><\/li><\/ul>\n\n\n\n<p>To use the autocomplete, just type one of the license abbreviations in the &#8220;Source&#8221; field and then move to another. <\/p>\n\n\n\n<p>If you are more technical, you can add new options using the <code>stockpack_autocomplete_licenses<\/code> filter like so:<br><\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"php\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">&lt;?php\n\n\nfunction stockpack_add_new_autocomplete_license( $options, $attachment ) {\n    \/\/ custom-new-slug is what you will type\n    $options['custom-new-slug'] = array(\n        'name' => 'Custom New License', \/\/ this is the name it will expand to\n        'url'  => 'https:\/\/custom.url' \/\/ this is the url it will use\n    );\n    \/\/ you can duplicate the lines above to add more options like so\n\/\/    $options['custom-new-slug2'] = array(\n\/\/        'name' => 'Second Custom New License', \/\/ this is the name it will expand to\n\/\/        'url'  => 'https:\/\/second-custom.url' \/\/ this is the url it will use\n\/\/    );\n\n    return $options;\n}\n\nadd_filter( 'stockpack_autocomplete_licenses', 'stockpack_add_new_autocomplete_license', 10, 2 );\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Changing the generated caption<\/h2>\n\n\n\n<p>While StockPack already has a filter for captions that are automatically pulled from the API <a href=\"https:\/\/stockpack.co\/blog\/changing-the-automated-captions\/\">here<\/a>, the captions that are generated work differently. <\/p>\n\n\n\n<p>To change the generated caption you can use the filter <code>stockpack_generated_caption<\/code><\/p>\n\n\n\n<p>Here&#8217;s how you can construct your own caption. It&#8217;s a long function because there are a lot of parts, but it&#8217;s very simple. Also, you can change what gets generated based on the source if you need different attribution based on the image source. <\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"php\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">&lt;?php\n\nfunction stockpack_change_generated_caption( $caption, $attachment ) {\n    $caption = __( 'Photo from', 'stockpack' ) . ' ';\n    \/** Author *\/\n    if ( isset( $attachment['stockpack_author_url'] ) &amp;&amp; $attachment['stockpack_author_url'] &amp;&amp; ( isset( $attachment['stockpack_author_name'] ) ) &amp;&amp; $attachment['stockpack_author_name'] ) {\n        $caption .= '&lt;a href=\"' . $attachment['stockpack_author_url'] . '\">';\n    }\n    if ( isset( $attachment['stockpack_author_name'] ) &amp;&amp; $attachment['stockpack_author_name'] ) {\n        $caption .= $attachment['stockpack_author_name'];\n    }\n\n    if ( isset( $attachment['stockpack_author_url'] ) &amp;&amp; $attachment['stockpack_author_url'] &amp;&amp; ( isset( $attachment['stockpack_author_name'] ) ) &amp;&amp; $attachment['stockpack_author_name'] ) {\n        $caption .= '&lt;\/a>';\n    }\n    \/** End Author *\/\n\n\n    \/** Provider\/Image title\/Image Source *\/\n    if ( ( isset( $attachment['stockpack_provider'] ) &amp;&amp; $attachment['stockpack_provider'] ) ) {\n        $caption .= ' ' . __( 'on', 'stockpack' ) . ' ';\n    }\n\n    if ( isset( $attachment['stockpack_image_url'] ) &amp;&amp; $attachment['stockpack_image_url'] &amp;&amp; ( isset( $attachment['stockpack_provider'] ) ) &amp;&amp; $attachment['stockpack_provider'] ) {\n        $caption .= '&lt;a href=\"' . $attachment['stockpack_image_url'] . '\">';\n    }\n\n    if ( isset( $attachment['stockpack_provider'] ) &amp;&amp; $attachment['stockpack_provider'] ) {\n        $caption .= $attachment['stockpack_provider'];\n    }\n\n    if ( isset( $attachment['stockpack_image_url'] ) &amp;&amp; $attachment['stockpack_image_url'] &amp;&amp; ( isset( $attachment['stockpack_provider'] ) ) &amp;&amp; $attachment['stockpack_provider'] ) {\n        $caption .= '&lt;\/a>';\n    }\n    \/** End Provider\/Image title\/Image Source *\/\n\n\n   \/** License *\/\n    if ( ( isset( $attachment['stockpack_license'] ) &amp;&amp; $attachment['stockpack_license'] ) || ( isset( $attachment['stockpack_license_url'] ) &amp;&amp; $attachment['stockpack_license_url'] ) ) {\n        $caption .= ' ' . __( 'used under', 'stockpack' ) . ' ';\n    }\n\n    if ( isset( $attachment['stockpack_license_url'] ) &amp;&amp; $attachment['stockpack_license_url'] &amp;&amp; ( isset( $attachment['stockpack_license'] ) &amp;&amp; $attachment['stockpack_license'] ) ) {\n        $caption .= '&lt;a href=\"' . $attachment['stockpack_license_url'] . '\">';\n    }\n\n    if ( isset( $attachment['stockpack_license'] ) &amp;&amp; $attachment['stockpack_license'] ) {\n        $caption .= $attachment['stockpack_license'];\n    }\n\n    if ( isset( $attachment['stockpack_license_url'] ) &amp;&amp; $attachment['stockpack_license_url'] &amp;&amp; ( isset( $attachment['stockpack_license'] ) &amp;&amp; $attachment['stockpack_license'] ) ) {\n        $caption .= '&lt;\/a>';\n    }\n    \/** End License *\/\n\n    if ( isset( $attachment['stockpack_modification'] ) &amp;&amp; $attachment['stockpack_modification'] ) {\n        $caption .= ' \/ ' . $attachment['stockpack_modification'];\n    }\n\n    return $caption;\n}\n\nadd_filter( 'stockpack_generated_caption', 'stockpack_change_generated_caption', 10, 2 );\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Featured image caption<\/h2>\n\n\n\n<p>As mentioned above, you can automatically show the caption for WordPress images using the setting under Advanced. This relies on a filter that the theme you are using should be using. <\/p>\n\n\n\n<p>You can also call the function manually in your loop <code>stockpack_featured_image_caption()<\/code><\/p>\n\n\n\n<p>If you have any questions, please <a href=\"https:\/\/stockpack.co\/contact\">reach out<\/a> or write to us in the comments. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Depending on the source of the images you are using, you might need to provide credit when using them. Or you just might want to do it, to appreciate the work of the author. Either way, you&#8217;ve come to the right place.<\/p>\n","protected":false},"author":1,"featured_media":550,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,8],"tags":[],"class_list":["post-549","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-documentation","category-wordpress"],"_links":{"self":[{"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/posts\/549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/comments?post=549"}],"version-history":[{"count":5,"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/posts\/549\/revisions"}],"predecessor-version":[{"id":559,"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/posts\/549\/revisions\/559"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/media\/550"}],"wp:attachment":[{"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/media?parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/categories?post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stockpack.co\/blog\/wp-json\/wp\/v2\/tags?post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}