Created
May 21, 2023 07:52
-
-
Save pouya1364/6fab104e8192a732776a5aad76062ef9 to your computer and use it in GitHub Desktop.
Wordpress YouTube playlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create a new file in your WordPress installation's wp-content/plugins directory. Name it something like youtube-playlist-creator.php. | |
Copy and paste the above code into the file. | |
Save the file. | |
Log in to your WordPress admin dashboard and go to the "Plugins" section. | |
You should see a new plugin called "YouTube Playlist Creator." Activate it. | |
Now, you can use the [youtube_playlist] shortcode in your WordPress posts or pages to embed a YouTube playlist. For example: | |
[youtube_playlist playlist_id="YOUR_PLAYLIST_ID"] | |
Replace YOUR_PLAYLIST_ID with the actual ID of your YouTube playlist. | |
Please note that this is a basic example to get you started. You can modify the code according to your specific requirements and add more features if needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: YouTube Playlist Creator | |
Description: Creates a YouTube playlist shortcode. | |
Version: 1.0 | |
Author: Your Name | |
*/ | |
// Register the shortcode | |
add_shortcode('youtube_playlist', 'youtube_playlist_shortcode'); | |
// Shortcode callback function | |
function youtube_playlist_shortcode($atts) { | |
// Get the playlist ID from the shortcode attributes | |
$atts = shortcode_atts(array( | |
'playlist_id' => '' | |
), $atts); | |
$playlist_id = $atts['playlist_id']; | |
// Check if the playlist ID is provided | |
if (empty($playlist_id)) { | |
return 'Please provide a playlist ID.'; | |
} | |
// Create the YouTube playlist embed code | |
$embed_code = '<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=' . $playlist_id . '" frameborder="0" allowfullscreen></iframe>'; | |
return $embed_code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment