{"id":4047,"date":"2023-08-13T17:35:51","date_gmt":"2023-08-13T15:35:51","guid":{"rendered":"https:\/\/www.knowboard.de\/?p=4047"},"modified":"2023-08-13T18:00:07","modified_gmt":"2023-08-13T16:00:07","slug":"make-featured-image-or-other-fields-mandatory-in-a-wordpress-post","status":"publish","type":"post","link":"https:\/\/www.knowboard.de\/make-featured-image-or-other-fields-mandatory-in-a-wordpress-post\/","title":{"rendered":"Make Featured Image or other Fields mandatory in a WordPress Post"},"content":{"rendered":"\n
EDIT: Does not work anymore. Still looking for a solution!<\/p>\n\n\n\n
<\/p>\n\n\n\n
\/\/You might want to add some instructions to the featured image field such as stating it is mandatory.\nfunction enym_add_featured_image_desc( $html ) {\n\n\tif(get_post_type() === 'inserat') {\n\t\t$html .= '<p><strong>Das erste Bild aus der Galerie wird automatisch als Vorschaubild definiert.<\/strong><\/p>'; \/\/<!-- Sie k\u00f6nnen aber auch manuell ein abweichendes Vorschaubild bestimmen. -->\n\t}\n\treturn $html;\n}\nadd_filter( 'admin_post_thumbnail_html', 'enym_add_featured_image_desc');\n\n\/\/MAKE FEATURED IMAGE OR OTHERS REQUIRED\nadd_action('admin_footer', 'enym_mandatory');\n\nfunction enym_mandatory(){\n\tglobal $typenow;\n\n\tif (in_array($typenow, array('inserat','post'))) { \/\/specify post type here such as post or page or event or comma separated multiple \n?>\n<script language=\"javascript\" type=\"text\/javascript\">\n\n\tjQuery(document).ready(function() {\n\n\t\t\/\/jQuery('#postimagediv .inside').append( \"<p class=\"hide-if-no-js howto\" id=\"set-post-thumbnail-desc\">Bild zum Bearbeiten oder \u00c4ndern anklicken.<\/p>\" );\n\n\n\t\tjQuery('#post').submit(function() {\n\n\t\t\tif (jQuery(\"#custombrandoptions\").val() != \"0\") {\n\t\t\t\tjQuery('#ajax-loading').hide();\n\t\t\t\tjQuery('#publish').removeClass('button-primary-disabled');\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\talert(\"Bitte bestimmen Sie Marke und Modell\");\n\t\t\t\tjQuery('#ajax-loading').hide();\n\t\t\t\tjQuery('#publish').removeClass('button-primary-disabled');\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t\/*\n\t\t\tif (jQuery(\"#set-post-thumbnail\").find('img').size() > 0 && jQuery(\"#custombrandoptions\").val() != \"0\") {\n\t\t\t\tjQuery('#ajax-loading').hide();\n\t\t\t\tjQuery('#publish').removeClass('button-primary-disabled');\n\t\t\t\treturn true;\n\t\t\t} else if (jQuery(\"#custombrandoptions\").val() === \"0\") {\n\t\t\t\talert(\"Bitte bestimmen Sie Marke und Modell\");\n\t\t\t\tjQuery('#ajax-loading').hide();\n\t\t\t\tjQuery('#publish').removeClass('button-primary-disabled');\n\t\t\t\treturn false;\n\t\t\t} else {\n\t\t\t\talert(\"Bitte w\u00e4hlen Sie ein Beitragsbild als Vorschau\");\n\t\t\t\tjQuery('#ajax-loading').hide();\n\t\t\t\tjQuery('#publish').removeClass('button-primary-disabled');\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t*\/\n\n\t\t\treturn false;\n\t\t});\n\t});\n<\/script>\n\n<?php\n\t}\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"EDIT: Does not work anymore. Still looking for a solution!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-4047","post","type-post","status-publish","format-standard","hentry","category-allgemein","entry","no-media"],"_links":{"self":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/4047"}],"collection":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/comments?post=4047"}],"version-history":[{"count":2,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/4047\/revisions"}],"predecessor-version":[{"id":4051,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/4047\/revisions\/4051"}],"wp:attachment":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/media?parent=4047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/categories?post=4047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/tags?post=4047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}