• I wrote a snippet to make the first image in a post the featured image, which works on my local install of WPCODE, but on the site, it won’t activate.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @kwoodall,

    When trying to activate the snippet on the website are you getting any error messages?

    Are the 2 sites identical? The first thing I would look at is making sure any function names used in the snippet are unique.

    Thread Starter kwoodall

    (@kwoodall)

    Temporarily I’ve put the code in functions.php where it works. But here’s the code I’m trying to make a snippet.

    function wpsites_auto_set_featured_image() {
       global $post;
    $featured_image_exists = has_post_thumbnail($post->ID);
    if (!$featured_image_exists)  {
     $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
    if ($attached_image) {
    foreach ($attached_image as $attachment_id => $attachment) {
    set_post_thumbnail($post->ID, $attachment_id);
    wp_reset_query();                                
       }
      }
     }
    }
    add_action('save_post', 'wpsites_auto_set_featured_image');
    
    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @kwoodall,

    Thank you for sharing the code, I tried it on my end and didn’t run into any issues activating the snippet.

    When you try to activate the snippet, what is the error message that you are receiving from the plugin?

    Can you please also try activating it from the list of snippets using the toggle there instead of from the edit screen?

    Thread Starter kwoodall

    (@kwoodall)

    I tried activating it both ways. And in both cases, it fails to activate and there’s no error message.

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @kwoodall,

    Do you have other WPCode snippets active that might be interfering?

    If you can share private access to the site with us please reach out via the form at https://wpcode.com/contact and we’ll gladly take a look to figure out what is preventing the snippet from being activated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can’t activate snippet’ is closed to new replies.