{"id":4933,"date":"2026-08-29T23:30:37","date_gmt":"2026-08-29T14:30:37","guid":{"rendered":"https:\/\/donguri3.net\/server-tech\/custom-sns-icons-cocoon-theme-2\/"},"modified":"2026-08-29T23:30:38","modified_gmt":"2026-08-29T14:30:38","slug":"custom-sns-icons-cocoon-theme","status":"publish","type":"post","link":"https:\/\/donguri3.net\/en\/server-tech\/wordpress-blog-seo\/custom-sns-icons-cocoon-theme\/","title":{"rendered":"[Cocoon] How to Add Custom SNS Icons to the Cocoon Theme"},"content":{"rendered":"<p>While WordPress&#8217;s popular &quot;Cocoon&quot; theme has built-in features to display SNS icons by default, you may sometimes want to add icons for services that aren&#8217;t supported out of the box. In this article, I&#8217;ll introduce how I used a Cocoon child theme to add custom SNS icons (for BOOTH, Patreon, and Marshmallow).<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li><strong>Do not edit the Cocoon parent theme<\/strong>; all customizations will be performed using only the Cocoon child theme (<code>functions.php<\/code> and <code>style.css<\/code>).<\/li>\n<\/ul>\n<div>\n<hr \/>\n<\/div>\n<h2>Adding Custom SNS Links to User Profiles<\/h2>\n<p>First, we will add custom fields to the WordPress user profile screen where users can enter their BOOTH, Patreon, and Marshmallow URLs. Add the following code to your child theme&#8217;s <code>functions.php<\/code>.<\/p>\n<h3>Adding Input Fields to the User Profile Edit Screen<\/h3>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">function add_custom_user_profile_field($user) {\n    ?&gt;\n    &lt;h3&gt;\u30ab\u30b9\u30bf\u30e0SNS\u30ea\u30f3\u30af&lt;\/h3&gt;\n    &lt;table class=&quot;form-table&quot;&gt;\n        &lt;tr&gt;\n            &lt;th&gt;&lt;label for=&quot;patreon&quot;&gt;Patreon URL&lt;\/label&gt;&lt;\/th&gt;\n            &lt;td&gt;\n                &lt;input type=&quot;text&quot; name=&quot;patreon&quot; id=&quot;patreon&quot; value=&quot;&lt;?php echo esc_attr(get_the_author_meta(&#039;patreon&#039;, $user-&gt;ID)); ?&gt;&quot; class=&quot;regular-text&quot; \/&gt;\n                &lt;br&gt;&lt;span class=&quot;description&quot;&gt;Patreon \u306e\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb URL \u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002&lt;\/span&gt;\n            &lt;\/td&gt;\n        &lt;\/tr&gt;\n        &lt;tr&gt;\n            &lt;th&gt;&lt;label for=&quot;booth&quot;&gt;BOOTH URL&lt;\/label&gt;&lt;\/th&gt;\n            &lt;td&gt;\n                &lt;input type=&quot;text&quot; name=&quot;booth&quot; id=&quot;booth&quot; value=&quot;&lt;?php echo esc_attr(get_the_author_meta(&#039;booth&#039;, $user-&gt;ID)); ?&gt;&quot; class=&quot;regular-text&quot; \/&gt;\n                &lt;br&gt;&lt;span class=&quot;description&quot;&gt;BOOTH \u306e\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb URL \u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002&lt;\/span&gt;\n            &lt;\/td&gt;\n        &lt;\/tr&gt;\n        &lt;tr&gt;\n            &lt;th&gt;&lt;label for=&quot;marshmallow&quot;&gt;\u30de\u30b7\u30e5\u30de\u30ed URL&lt;\/label&gt;&lt;\/th&gt;\n            &lt;td&gt;\n                &lt;input type=&quot;text&quot; name=&quot;marshmallow&quot; id=&quot;marshmallow&quot; value=&quot;&lt;?php echo esc_attr(get_the_author_meta(&#039;marshmallow&#039;, $user-&gt;ID)); ?&gt;&quot; class=&quot;regular-text&quot; \/&gt;\n                &lt;br&gt;&lt;span class=&quot;description&quot;&gt;\u30de\u30b7\u30e5\u30de\u30ed \u306e\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb URL \u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002&lt;\/span&gt;\n            &lt;\/td&gt;\n        &lt;\/tr&gt;\n    &lt;\/table&gt;\n    &lt;?php\n}\nadd_action(&#039;show_user_profile&#039;, &#039;add_custom_user_profile_field&#039;);\nadd_action(&#039;edit_user_profile&#039;, &#039;add_custom_user_profile_field&#039;);<\/pre>\n<h3>Saving the Entered URLs<\/h3>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">function save_custom_user_profile_fields($user_id) {\n    if (!current_user_can(&#039;edit_user&#039;, $user_id)) {\n        return false;\n    }\n    if (isset($_POST&#x5B;&#039;patreon&#039;])) {\n        update_user_meta($user_id, &#039;patreon&#039;, $_POST&#x5B;&#039;patreon&#039;]);\n    }\n    if (isset($_POST&#x5B;&#039;booth&#039;])) {\n        update_user_meta($user_id, &#039;booth&#039;, $_POST&#x5B;&#039;booth&#039;]);\n    }\n    if (isset($_POST&#x5B;&#039;marshmallow&#039;])) {\n        update_user_meta($user_id, &#039;marshmallow&#039;, $_POST&#x5B;&#039;marshmallow&#039;]);\n    }\n}\nadd_action(&#039;personal_options_update&#039;, &#039;save_custom_user_profile_fields&#039;);\nadd_action(&#039;edit_user_profile_update&#039;, &#039;save_custom_user_profile_fields&#039;);<\/pre>\n<div>\n<hr \/>\n<\/div>\n<h2>Customizing to Display SNS Icons<\/h2>\n<p>Next, we will display the added SNS links on the site and apply custom images as icons.<\/p>\n<h3>Downloading SNS Icons<\/h3>\n<p>Since we are using SNS icons for BOOTH, Patreon, and Marshmallow, download the logos from each official website. Please thoroughly read and follow each site&#8217;s guidelines regarding logo usage.<\/p>\n<ul>\n<li><strong>BOOTH<\/strong>: <a href=\"https:\/\/www.pixiv.co.jp\/news\/press-kit\/\">https:\/\/www.pixiv.co.jp\/news\/press-kit\/<\/a><\/li>\n<li><strong>Patreon<\/strong>: <a href=\"https:\/\/www.patreon.com\/ja-JP\/brand\">https:\/\/www.patreon.com\/ja-JP\/brand<\/a><\/li>\n<li><strong>Marshmallow<\/strong>: <a href=\"https:\/\/help.marshmallow-qa.com\/--66e2538617c946001d347fd3\">https:\/\/help.marshmallow-qa.com\/&#8211;66e2538617c946001d347fd3<\/a><\/li>\n<\/ul>\n<h3>Code to Display SNS Icons<\/h3>\n<p>Add code to the child theme&#8217;s <code>functions.php<\/code> and <code>style.css<\/code> to enable displaying your own custom SNS icons.<\/p>\n<h4>Adding SNS Follow Buttons<\/h4>\n<p>Add the following code to the child theme&#8217;s <code>functions.php<\/code> so that your custom SNS follow buttons can be rendered.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\/\/ SNS\u30d5\u30a9\u30ed\u30fc\u30dc\u30bf\u30f3\u306e\u51fa\u529b\u3092\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3057\u3066SNS\u30d5\u30a9\u30ed\u30fc\u30dc\u30bf\u30f3\u3092\u8ffd\u52a0\nfunction add_patreon_follow_button($content) {\n    $user_id = get_the_posts_author_id();\n    $patreon_url = get_the_author_meta(&#039;patreon&#039;, $user_id);\n    $booth_url = get_the_author_meta(&#039;booth&#039;, $user_id);\n    $marshmallow_url = get_the_author_meta(&#039;marshmallow&#039;, $user_id);\n\n    $content .= &#039;&quot;&gt;&lt;div class=&quot;sns-follow-buttons sns-buttons&quot;&gt;&#039;;\n\n    if ($patreon_url) {\n        $button_html = &#039;&lt;a href=&quot;&#039; . esc_url($patreon_url) . &#039;&quot; class=&quot;sns-button follow-button patreon-button patreon-follow-button-sq&quot; target=&quot;_blank&quot; title=&quot;Patreon\u3092\u30d5\u30a9\u30ed\u30fc&quot; rel=&quot;nofollow noopener noreferrer&quot; aria-label=&quot;Patreon\u3092\u30d5\u30a9\u30ed\u30fc&quot;&gt;&lt;span class=&quot;icon-patreon-logo&quot;&gt;&lt;\/span&gt;&lt;\/a&gt;&#039;;\n        $content .= $button_html;\n    }\n    if($booth_url) {\n        $button_html = &#039;&lt;a href=&quot;&#039; . esc_url($booth_url) . &#039;&quot; class=&quot;sns-button follow-button booth-button booth-follow-button-sq&quot; target=&quot;_blank&quot; title=&quot;BOOTH\u3092\u30d5\u30a9\u30ed\u30fc&quot; rel=&quot;nofollow noopener noreferrer&quot; aria-label=&quot;BOOTH\u3092\u30d5\u30a9\u30ed\u30fc&quot;&gt;&lt;span class=&quot;icon-booth-logo&quot;&gt;&lt;\/span&gt;&lt;\/a&gt;&#039;;\n        $content .= $button_html;\n    }\n    if ($marshmallow_url) {\n        $button_html = &#039;&lt;a href=&quot;&#039; . esc_url($marshmallow_url) . &#039;&quot; class=&quot;sns-button follow-button marshmallow-button marshmallow-follow-button-sq&quot; target=&quot;_blank&quot; title=&quot;\u30de\u30b7\u30e5\u30de\u30ed\u3092\u30d5\u30a9\u30ed\u30fc&quot; rel=&quot;nofollow noopener noreferrer&quot; aria-label=&quot;\u30de\u30b7\u30e5\u30de\u30ed\u3092\u30d5\u30a9\u30ed\u30fc&quot;&gt;&lt;span class=&quot;icon-marshmallow-logo&quot;&gt;&lt;\/span&gt;&lt;\/a&gt;&#039;;\n        $content .= $button_html;\n    }\n    $content .= &#039;&lt;\/div &quot;&#039;;\n    return $content;\n}\nadd_filter(&#039;get_additional_sns_follow_button_classes&#039;, &#039;add_patreon_follow_button&#039;);<\/pre>\n<p>In this approach, we filter the <code>get_additional_sns_follow_button_classes<\/code> function from Cocoon&#8217;s <code>tmp\/sns-follow-buttons.php<\/code> to inject custom SNS buttons. However, this method results in a new <code>&lt;div class=&#8221;sns-follow-buttons sns-buttons&#8221;&gt;<\/code> being added right above the original <code>&lt;div class=&#8221;sns-follow-buttons sns-buttons&#8221;&gt;<\/code>, making it a slightly forceful approach.<\/p>\n<hr \/>\n<h4>Styling Icons with CSS<\/h4>\n<p>Add the following to your <code>style.css<\/code> to apply the icon images.<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">.icon-booth-logo {\n    display: inline-block;\n    width: 30px;\n    height: 30px;\n    background: url(&#039;&lt;upload\u3057\u305f\u30ed\u30b4\u3078\u306e\u30d1\u30b9&gt;&#039;) no-repeat center \/ contain !important;\n}\n&#x5B;class*=bc-brand-color] .booth-button {\n    --cocoon-sns-color: #FC4D50;\n}\n\n.icon-patreon-logo {\n    display: inline-block;\n    width: 27.4px;\n    height: 30px;\n    background: url(&#039;&lt;upload\u3057\u305f\u30ed\u30b4\u3078\u306e\u30d1\u30b9&gt;&#039;) no-repeat center \/ contain !important;\n}\n&#x5B;class*=bc-brand-color] .patreon-button {\n    --cocoon-sns-color: #f96854;\n}\n\n.icon-marshmallow-logo {\n    display: inline-block;\n    width: 30px;\n    height: 30px;\n    background: url(&#039;&lt;upload\u3057\u305f\u30ed\u30b4\u3078\u306e\u30d1\u30b9&gt;&#039;) no-repeat center \/ contain !important;\n}\n&#x5B;class*=bc-brand-color] .marshmallow-button {\n    --cocoon-sns-color: #F3969A;\n}<\/pre>\n<p><strong>Note:<\/strong> You may encounter an issue where specifying an image using <code>background-image<\/code> causes the <code>background-size<\/code> property to be ignored. To avoid this, use the <code>background<\/code> shorthand property, which ensures <code>background-size<\/code> is applied correctly as well.<\/p>\n<h2>How to Use<\/h2>\n<ol start=\"1\">\n<li>Enter your URLs into the custom SNS link fields created at the bottom of your profile page and save.<\/li>\n<li>Visit a page that displays SNS follow buttons to verify.<\/li>\n<li>If they do not appear, clear your WordPress cache and browser cache.<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>This successfully adds BOOTH, Patreon, and Marshmallow SNS icons to the Cocoon theme. By creating custom fields in user profiles and displaying the icons on your site, you can easily guide visitors to your pages on each service.<\/p>\n<p>If you know of any plugins or resources that make adding SNS icons or creating custom buttons even easier, please let me know!<br \/>\nAlso, any advice on how to align the icons nicely side-by-side would be greatly appreciated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While WordPress&#8217;s popular &quot;Cocoon&quot; theme has built-in features to display SNS icons by default [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1098,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/donguri3.net\/?p=524","footnotes":""},"categories":[1166],"tags":[164,52,61,179,181],"class_list":["post-4933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-blog-seo","tag-cocoon","tag-https","tag-wordpress","tag-179","tag-181","en-US"],"_links":{"self":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/comments?post=4933"}],"version-history":[{"count":1,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4933\/revisions"}],"predecessor-version":[{"id":4936,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/4933\/revisions\/4936"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media\/1098"}],"wp:attachment":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media?parent=4933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/categories?post=4933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/tags?post=4933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}