There appear to be a few problems with your plugin as written.
- As mentioned in the comments above, WordPress has the built-in ability to automatically embed certain types of media, including YouTube videos, given a URL. See the Codex page on Embeds. So it’s likely that your plugin isn’t necessary, at least for a YouTube embed.
the_content
is a filter hook, not an action hook. So typically you’d useadd_filter()
to filter the post’s content.- Even if you were to attach your function to a proper action hook, you wouldn’t see any output from it. Your function, as written,
return
s a variable, butadd_action()
ignores yourreturn
— according to the Codex,add_action()
always returnstrue
.
Actions typically either echo()
content to the screen (well, the response buffer) or modify a variable; Filters typically accept one or more variables, and return a (possibly modified) version of that variable. See this question for an in-depth look at the differences.