Title: Complex Logic
Last modified: January 5, 2023

---

# Complex Logic

 *  Resolved [pharmanext](https://wordpress.org/support/users/pharmanext/)
 * (@pharmanext)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/complex-logic/)
 * Hi,
 * I’m asking for your help in implementing the algorithm for displaying ads.
 * Right now the algorithm is as follows:
 *     ```wp-block-code
       [ADINSERTER CHECK countries="G1"]
   
       [ADINSERTER VIEWPORT="Desktop"]
   
       AdCode_for_G1_desktop
   
       [ADINSERTER VIEWPORT="Phone"]
   
       AdCode_for_G1_mobile
   
   
       [ADINSERTER CHECK countries="^G1"]
   
   
       [ADINSERTER ROTATE name="Ad1"]
   
       [ADINSERTER VIEWPORT="Desktop"]
   
       AdCode_for_non-G1_desktop_Rotation-1
   
       [ADINSERTER VIEWPORT="Phone"]
   
       AdCode_for_non-G1_mobile_Rotation-1
   
   
       [ADINSERTER ROTATE name="Ad2"]
   
       [ADINSERTER VIEWPORT="Desktop"]
   
       AdCode_for_non-G1_desktop_Rotation-2
   
       [ADINSERTER VIEWPORT="Phone"]
   
       AdCode_for_non-G1_mobile_Rotation-2
       ```
   
 * I need to insert an additional ad code (let’s call it AddonAdCode).
 * Insertion options and related questions are as follows, and I’ll start by shortcode
   priority:
 * Where should AddonAdCode be inserted so that it is inserted regardless of the**
   CHECK** countries shortcode, that is, in both _G1_ and _^G1_?
 * Where should AddonAdCode be inserted so that it is inserted regardless of the**
   ROTATE** shortcode, i.e. in both _Ad1_ and _Ad2_?
 * Where should the AddonAdCode be inserted so that it is inserted regardless of
   the **VIEWPORT** shortcode, i.e. in both _Desktop_ and _Phone_ (for example, 
   in the _^G1_ –> _Ad2_ section)?
 * Thank you in advance for your reply.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/complex-logic/#post-16345777)
 * Hello,
 * here are the answers:
 * > Where should AddonAdCode be inserted so that it is inserted regardless of the**
   > CHECK** countries shortcode, that is, in both _G1_ and _^G1_?
 * It needs to be inserted into both CHECK options.
 * > Where should AddonAdCode be inserted so that it is inserted regardless of the**
   > ROTATE** shortcode, i.e. in both _Ad1_ and _Ad2_?
 * It needs to be inserted into all ROTATE options.
 * > Where should the AddonAdCode be inserted so that it is inserted regardless 
   > of the **VIEWPORT** shortcode, i.e. in both _Desktop_ and _Phone_ (for example,
   > in the _^G1_ –> _Ad2_ section)?
 * It should be inserted above the first VIEWPORT shortcode.
 * However, in this case it would be much easier to simply insert one additional
   block with AddonAdCode at the same position as the code above.
 *  Thread Starter [pharmanext](https://wordpress.org/support/users/pharmanext/)
 * (@pharmanext)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/complex-logic/#post-16346364)
 * Thank you very much for your response.
 * 
   Since the logic of Ad Inserter often involves a lot of code duplication, could
   you please tell me if you had any thoughts of changing the existing logic in 
   any way to make it more optimal? Obviously, such a strong change would require
   a complete overhaul.
 *  Plugin Author [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/complex-logic/#post-16347040)
 * Yes, already on the todo list.
 *  Plugin Author [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/complex-logic/#post-16351641)
 * The latest development version already supports options to append or prepend 
   code to each rotation option:
   [https://downloads.wordpress.org/plugin/ad-inserter.zip](https://downloads.wordpress.org/plugin/ad-inserter.zip)
 * `[ADINSERTER ROTATE code="APPEND"]
   CODE TO APPEND
 * `[ADINSERTER ROTATE CODE="PREPEND"]
   CODE TO PREPEND

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Complex Logic’ is closed to new replies.

 * ![](https://ps.w.org/ad-inserter/assets/icon-256x256.jpg?rev=1502039)
 * [Ad Inserter - Ad Manager & AdSense Ads](https://wordpress.org/plugins/ad-inserter/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ad-inserter/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ad-inserter/)
 * [Active Topics](https://wordpress.org/support/plugin/ad-inserter/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ad-inserter/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ad-inserter/reviews/)

## Tags

 * [check](https://wordpress.org/support/topic-tag/check/)
 * [rotate](https://wordpress.org/support/topic-tag/rotate/)
 * [viewport](https://wordpress.org/support/topic-tag/viewport/)

 * 4 replies
 * 2 participants
 * Last reply from: [Spacetime](https://wordpress.org/support/users/spacetime/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/complex-logic/#post-16351641)
 * Status: resolved