{"id":233083,"date":"2023-02-05T10:54:00","date_gmt":"2023-02-05T07:54:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=233083"},"modified":"2023-02-05T11:04:38","modified_gmt":"2023-02-05T08:04:38","slug":"hur-tillaater-jag-bilder-istaellet-foer-url-i-wordpress-kommentarer","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/sv\/hur-tillaater-jag-bilder-istaellet-foer-url-i-wordpress-kommentarer\/","title":{"rendered":"Hur till\u00e5ter jag bilder ist\u00e4llet f\u00f6r URL i WordPress-kommentarer?"},"content":{"rendered":"<p>Som standard beh\u00e5lls webbadresserna i kommentaren som de \u00e4r. Om en anv\u00e4ndare l\u00e4gger in en bild-URL direkt, skulle det vara trevligt att ers\u00e4tta URL-adressen med den faktiska HTML-img-taggen. L\u00e4gg till f\u00f6ljande <a href=\"https:\/\/wordpress.mediadoma.com\/sv\/hur-cachelagrar-jag-wechat-token-via-php\/\" title=\"PHP-kod\">PHP-kod<\/a> i ditt <a href=\"https:\/\/helloacm.com\/how-to-remove-product-review-in-woocommercewordpress\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">wordpress<\/a> &#8211; tema <a href=\"https:\/\/helloacm.com\/how-to-remove-admin-topbar-in-wordpress\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">functions.php<\/a> :<\/p>\n<pre><code>\/\/ empty - allow all posts, otherwise, put post IDs joined by comma\ndefine('ALLOW_POSTS', '');\nfunction helloacm_allow_comment_image( $comment) {\n\u00a0 \u00a0 $post_ID = $comment[\"comment_post_ID\"];\n\u00a0 \u00a0 $allow_posts = ALLOW_POSTS? explode(',', ALLOW_POSTS): array();\n\u00a0 \u00a0 if(empty($allow_posts) || in_array($post_ID, $allow_posts)){\n\u00a0 \u00a0 \u00a0 \u00a0 global $allowedtags;\n\u00a0 \u00a0 \u00a0 \u00a0 $content = $comment[\"comment_content\"];\n\u00a0 \u00a0 \u00a0 \u00a0 $content = preg_replace('\/(https?:\/\/S+.(?:jpg|png|jpeg|gif|bmp))+\/','&lt;img \u00a0title=\"$0 How to Allow Images Instead of URL in WordPress Comments? wordpress \" src=\"$0\" \u00a0alt=\"$0 How to Allow Images Instead of URL in WordPress Comments? wordpress \" \u00a0\/&gt;',$content);\n\u00a0 \u00a0 \u00a0 \u00a0 $allowedtags['img'] = array('src' =&gt; array(), 'alt' =&gt; array());\n\u00a0 \u00a0 \u00a0 \u00a0 $comment[\"comment_content\"] = $content;\n\u00a0 \u00a0 }\n\u00a0 \u00a0 return $comment;\n}\nadd_filter('preprocess_comment', 'helloacm_allow_comment_image');<\/code><\/pre>\n<p>Vi anv\u00e4nder ett regulj\u00e4rt uttryck f\u00f6r att hitta bildwebbadresser (som slutar med till\u00e4ggen jpg\/png\/jpeg\/gif\/bmp) och ers\u00e4tter med HTML-taggen img. Vi m\u00e5ste ocks\u00e5 till\u00e5ta IMG-taggen i kommentarsektionen f\u00f6r att kunna visa den korrekt. Ovanst\u00e5ende funktion m\u00e5ste l\u00e4ggas till i filtret preprocess_comment som anropas innan en kommentar infogas i <a href=\"https:\/\/helloacm.com\/easy-round-robin-scheduled-database-backup-on-linux\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">databasen<\/a>.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Inspelningsk\u00e4lla:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hur till\u00e5ter jag bilder ist\u00e4llet f\u00f6r URL i WordPress-kommentarer?<\/p>\n","protected":false},"author":1,"featured_media":224757,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[838,848,901,807,868],"tags":[1173],"class_list":["post-233083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide-foer-nyboerjare","category-handledningar","category-koda","category-php-9","category-wordpress-9","tag-affiai-sv"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/posts\/233083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/comments?post=233083"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/posts\/233083\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/media\/224757"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/media?parent=233083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/categories?post=233083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/sv\/wp-json\/wp\/v2\/tags?post=233083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}