{"id":964,"date":"2024-11-21T04:55:57","date_gmt":"2024-11-21T10:55:57","guid":{"rendered":"https:\/\/thecweb.com\/?p=964"},"modified":"2024-11-21T05:12:24","modified_gmt":"2024-11-21T11:12:24","slug":"last-coat-of-paint-is-drying","status":"publish","type":"post","link":"https:\/\/thecweb.com\/index.php\/2024\/11\/21\/last-coat-of-paint-is-drying\/","title":{"rendered":"Last coat of paint is drying"},"content":{"rendered":"\n<p>This ended up being a lot more research for very little change, but I&#8217;m happy so far.  I may still adjust some colors, but other than that I&#8217;m happy.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"303\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2024\/11\/image-5-1024x303.png\" alt=\"\" class=\"wp-image-975\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2024\/11\/image-5-1024x303.png 1024w, https:\/\/thecweb.com\/wp-content\/uploads\/2024\/11\/image-5-300x89.png 300w, https:\/\/thecweb.com\/wp-content\/uploads\/2024\/11\/image-5-768x227.png 768w, https:\/\/thecweb.com\/wp-content\/uploads\/2024\/11\/image-5-1536x454.png 1536w, https:\/\/thecweb.com\/wp-content\/uploads\/2024\/11\/image-5.png 1640w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>What I ended up spending the most time on was a simple feature that required php code to work. I wanted to set the first image in the post as the WP Feature Image for the post. I am really surprised this feature isn&#8217;t part of word press to be honest.<\/p>\n\n\n\n<p>Here is the code that I had to add to my functions.php file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ add support for Feature Image.  Pobably redundent as it should be in parent theme\nadd_theme_support( 'post-thumbnails' );\n\n\/\/ \/\/ autoset_featured is a function that sets the featured image to the first image in the post\nfunction autoset_featured() {\n    global $post;\n    $already_has_thumb = has_post_thumbnail($post-&gt;ID);\n    if (!$already_has_thumb)  {\n        $attached_image = get_children(\"post_parent=$post-&gt;ID&amp;post_type=attachment&amp;post_mime_type=image&amp;numberposts=1\" );\n            if ($attached_image) {\n                foreach ($attached_image as $attachment_id =&gt; \n                $attachment) {\n                    set_post_thumbnail($post-&gt;ID, $attachment_id);\n                }\n            }\n        }\n    }\nadd_action('the_post', 'autoset_featured');\nadd_action('save_post', 'autoset_featured');\nadd_action('draft_to_publish', 'autoset_featured');\nadd_action('new_to_publish', 'autoset_featured');\nadd_action('pending_to_publish', 'autoset_featured');\nadd_action('future_to_publish', 'autoset_featured');<\/code><\/pre>\n\n\n\n<p>Unfortunately, there was several hours of research and missteps to get this working properly, and the way I wanted.  <\/p>\n\n\n\n<p>I started by reading the first several sections of the <a href=\"https:\/\/developer.wordpress.org\/themes\/\">WordPress Developer Theme Handbook.<\/a>  This was more interesting than you&#8217;d think, and I know how a much better idea about where things go.  Specifically, the functions.php file(in my <a href=\"https:\/\/wpmudev.com\/blog\/how-to-create-wordpress-child-theme\/\">child theme<\/a>, which I now know I should create).<\/p>\n\n\n\n<p>Then I found <a href=\"https:\/\/firstsiteguide.com\/wordpress-featured-image\/\">this person&#8217;s code<\/a> and just copy and pasted it.  Which sounds lazy, but I know what all the code does at the moment, which is nice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This ended up being a lot more research for very little change, but I&#8217;m happy so far. I may still adjust some colors, but other than that I&#8217;m happy. What I ended up spending the most time on was a simple feature that required php code to work. I wanted to set the first image [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-964","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=964"}],"version-history":[{"count":3,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/964\/revisions"}],"predecessor-version":[{"id":976,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/964\/revisions\/976"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/media\/975"}],"wp:attachment":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}