• 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

A/B test an ad with different hooks

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 › A/B test an ad with different hooks

This topic is: resolved

Tagged: ads, functions.php, hooks, php

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

    Have a PHP function for wordpress in my functions.php to display an adsense ad in my posts using a Hook:
    genesis_before_loop
    Function 1:

        add_action('genesis_before_loop', 'topadd');
        function topadd()
        {
        	if(  is_singular('post') ){
        ?>
           <div class="topadd">
                <div class="wrap">
        <!-- ADSENSE AD1 -->
                </div>
            </div>
        <?php
        	}
        }  

    However I want to A/B test this ad in this hook vs this one:
    genesis_after_header
    Function 2 is:

        add_action('genesis_after_header', 'topadd');
        function topadd()
        {
        	if(  is_singular('post') ){
        ?>
           <div class="topadd">
                <div class="wrap">
        <!-- ADSENSE AD2 -->
                </div>
            </div>
        <?php
        	}
        }  

    To A/B/n test inside a php function I use this:

        <?php 
        $option[0] = ' adsense_code_1 ';  
        $option[1] = ' adsense_code_2 ';  
        $option[2] = ' adsense_code_3 ';  
        $option[3] = ' adsense_code_4 ';
        $option[n] = ' adsense_code_n ';
        echo $option[rand()%count($option)];  
        ?>  

    But it wont work to rotate functions so what Im looking is:

    A code to use in functions.php to rotate/split test my:
    Function 1
    Function 2

    January 21, 2015 at 6:52 am #138171
    Susan
    Moderator

    I am closing this thread, as you have marked it as "resolved". Please start a new thread if you have another question.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘A/B test an ad with different hooks’ is closed to new 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