Editing a pre-built template. Some things are pure HTML inside the template, that I cannot add via Admin Panel. For example: Embed youtube video at a specific point.


Is there any plugin that allows me creating parametes via shortcodes, and then assign values to those parameters from the Wordpress admin panel?

Inside the theme HTML: [PARAM youtubehome]
In the Control Panel: "Paramenter youtubename: __________"

So I can edit all those parameters without editing the code again?

Thanks for your time :)

  • Custom hooks will be better in this case IMO. However, if you want to add the video inside of the post content, shortcodes will be better. – Abhik Sep 22 '15 at 11:00
  • I also think that using shortocodes directly in PHP files are not good idea, it is better to use template tags (they can be reused from shortcode callbacks, if you still want to code the shortocde to be used anywhere else). And for embed youtube videos, instead of shortcodes, oEmbed API is really better. You can see the list of oEmbed providers already supported in the core here. – cybmeta Sep 22 '15 at 11:21

Of course. You need two things - a settings page, and a custom shortcode handler. The first is a little too broad to discuss in detail here, but this tutorial should help get you started. You can also check out the codex, or post back here with a new question if you really get stuck.

Now for the shortcode:

function wpse_203387_param_shortcode( $atts ) {
    // [PARAM name="data"], $atts will be an array of name => data pairs
    // [PARAM data], $atts will be a numeric array with one element, "data"

    // In this case, we just always grab the first value/data
    $name = array_shift( $atts );

    switch ( strtolower( $name ) ) {
        case 'youtubehome' : // [PARAM youtubehome]
            $data = get_option( 'theme_options' ); // This is purely for example, use the data structure/names that match your settings API config

            return $data['youtube_setting'];

        case 'anotherparam' : // [PARAM anotherparam]
            return 'something_else';

add_shortcode( 'PARAM', 'wpse_203387_param_shortcode' );

Update: To allow other roles (capabilities) to update your settings:

function wpse_203387_options_page_capability( $capability ) {
    return 'edit_theme_options';

add_filter( 'option_page_capability_my-theme-settings-name', 'wpse_203387_options_page_capability' );
|improve this answer|||||
  • Thank you very much for taking your time. I will then proceed with creating both the setting pages and custom params. But, I read in Codex: "When using the Settings API, the form posts to wp-admin/options.php which provides fairly strict capabilities checking. Users will need 'manage_options' capability (and in MultiSite will have to be a Super Admin) to submit the form.". Does this mean that in Multisite the Setting Pages for a specific site will not work if the user is not Super Admin? (In that case: what is left as an alternative?) Thanks again for such a detailed answer. – Álvaro N. Franz Sep 22 '15 at 11:16
  • Since 3.2 you can set which capability a user needs to update your option. – TheDeadMedic Sep 22 '15 at 11:23
  • I really appreciate your help, will now research about everything. Stay strong, good luck! :) – Álvaro N. Franz Sep 22 '15 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.