• Resolved baz74

    (@baz74)


    On the home page, we would like to display one of two carousels – chosen randomly.

    Would someone help me with php syntax for something like:
    rand(1,5)
    if 1,2,3 -> display shortcode[A]
    else -> display shortcode[B]
    (i.e. A slighly more often than B).

    We could put the php in the Snippits plugin.
    What do we put in the home Page – to get it to only run on this page? And to document/explain to some later developer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Untested, but it should work something like this:

    add_shortcode( 'random_gallery', function() {
    $shortcodes = array(
    '[shortcode1]',
    '[shortcode1]',
    '[shortcode1]',
    '[shortcode2]',
    '[shortcode2]',
    );
    return do_shortcode($shortcodes[wp_rand(0, count($shortcodes) - 1)]);
    });

    You would have to use the shortcode [random_gallery] where it is to be output.

    Hello,

    This forum is for assistance with issues with WordPress. If you need professional coding assistance, you can go to https://jobs.wordpress.net/ and post your project there.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help with writing some php please for random block selection.’ is closed to new replies.