• Resolved hwtech

    (@hwtech)


    say I define an environment variable in wp-config
    define(‘PHOTOBASE_URL’, ‘https://somedomain.com/photos’);.

    how can I access that variable in a html shortcode (say using shortcoder)

    The idea is this case is to use it in an img tag so that the user only enters their photo filename as a parameter and the shortcode creates the full URL.

    I suppose I could access it via php in the short code like this
    <?php $url = PHOTOBASE_URL ?>

    then in some html
    <img src=”<?= $url ?>%%filename%%” >

    but is does the shortcode api have a way to identify/parse these in the html maybe using some special delimiters?

    I’ve done this in a static site generator, Hugo, that supports shortcodes but there is an easy syntax for accessing site object variables in the hmtl.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Any value that’s defined using define() is available in any PHP code in the site (after the define() is called at least).

    That means that this will work in any HTML area that you want to use it in:

    <img src="<?php echo PHOTOBASE_URL; ?>&&filename%%">

    Thread Starter hwtech

    (@hwtech)

    thx, that works, all in one line.

    Just in case some uses this I corrected your code for with the missing shortcoder variable delimiter

    <img src="<?php echo PHOTOBASE_URL; ?>&&%%filename%%">

    just thought WP might support special delimiters for access to app defined variables kinda like the double % used by shortcoder.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘config file defined value used in a shortcoe’ is closed to new replies.