• Hello,
    for my design it is more complaisant to use shortcodes instead
    of url because the shortcode provides some additional formatting.

    Example:
    When you like to have a shortcode resolved by a main menu item,
    this seems not to be possible and also plugins are not really working
    (in my case).

    When you like to add a RSS feed to sidebar, only an URL is accepted,
    not a shortcode which could implement this RSS more convenient.

    (To be able to use shortcodes where ever URL is accepted would be a nice
    standard feature for next WP release. If you can’t extract url from shortcode -> 404).

    My question:
    Is there a general workaround to use shortcodes in URL fields, like functions handle this ?
    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    If you mean allowing a user to enter a shortcode in place of an URL in an existing form, as in a widget settings field for example, then no, it’s not possible.

    However, if you were to create a custom template, widget, etc., where handling shortcodes is part of the design, then it is possible. You basically need to run any possible URL/shortcode value through do_shortcode() before output.

    Typically, you might get a value from the DB and then do echo $value; for output. This cannot accommodate shortcodes that may be part of $value. To accommodate possible shortcodes, do this instead: echo do_shortcode( $value );

    Thread Starter wpbetheme789

    (@wpbetheme789)

    Hello,
    i primarily want to be able to link a shortcode to a menu item.
    It seems that menu items only accept url.

    Already tested a plugin that promised to do that but it did not work.
    Thank you for help

    Moderator bcworkz

    (@bcworkz)

    If I’m not mistaken, you can enter anything you like as a menu URL, but of course it’s not going to work as a link. Certainly shortcodes are not expanded this way by default. You should be able to hook the wp_nav_menu filter and run the passed HTML through do_shortcode(). Your theme would need to use wp_nav_menu() to output the menu. This is highly likely, most themes do this. It’s more something to investigate if my suggestion doesn’t work.

    Keep in mind WP places ‘https://’ in front of whatever is entered, so your shortcode should not include this. If it does and it’s difficult to alter the shortcode expansion, your filter callback could search for double https and strip out one of them.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to use shortcode where URL is expected’ is closed to new replies.