• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Randomize a Hook Function in my functions.php to A/B test an ad

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Randomize a Hook Function in my functions.php to A/B test an ad

This topic is: not resolved

Tagged: a/b test, functions.php, hooks, randomize, rotate

  • This topic has 1 reply, 1 voice, and was last updated 8 years ago by iamzeus.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • January 20, 2015 at 11:43 am #138089
    iamzeus
    Member

    Have an add_action my functions.php to display an adsense ad in my posts using a Hook:
    genesis_after_header
    add_action('genesis_after_header', 'topadd0');

    However I want to A/B test this Hook&Ad vs Another Hook&Ad:
    genesis_before_loop:
    add_action('genesis_before_loop', 'topadd1');

    How can I randomize the add_action to display only 1 in my page, either:
    add_action('genesis_after_header', 'topadd0');
    or
    add_action('genesis_before_loop', 'topadd1');

    January 20, 2015 at 2:33 pm #138122
    iamzeus
    Member

    Something like:

    add_action( 'genesis_meta', 'randomhook' );
    function randomhook() {
    $option[0] = add_action('genesis_after_header', 'topadd0');
    $option[1] = add_action('genesis_before_loop', 'topadd1');
    return $option[rand()%count($option)];
    }

    But this one isnt really working

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble