chat gpt generated plugin for embedding subreddit not working

[ad_1]

I had chat gpt create a piece of code that i uploaded as a plug in into wordpress. the goal is to have my site host an embedded version of my sub. the code seems straight foreward, but when i call the short code, i get a message that it cannot connect to reddit.com . is there some sort of permissions i am not obtaining from reddit or is there an error in the code?

​

<?php
/*
Plugin Name: Subreddit Embed
Description: Embeds a subreddit using a link
Version: 1.0
Author: Your Name
*/

// Define the shortcode to use in the post editor
add_shortcode( ‘subreddit’, ’embed_subreddit’ );

// Function that will embed the subreddit
function embed_subreddit( $atts ) {
// Get the link from the shortcode attributes
$link = $atts[‘link’];

// Extract the subreddit name from the link
$subreddit = preg_replace(‘/https?:\/\/(www\.)?reddit.com\/r\//’, ”, $link);

// Build the embed HTML
$html = ‘<iframe src=”https://www.reddit.com/r/’.$subreddit.’/embed” width=”100%” height=”600″ frameborder=”0″></iframe>’;

// Return the embed HTML
return $html;
}

[ad_2]
1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer