Title: Shortcode creating two pages
Last modified: January 31, 2022

---

# Shortcode creating two pages

 *  [Daddio](https://wordpress.org/support/users/thomasdickerson/)
 * (@thomasdickerson)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/shortcode-creating-two-pages/)
 * I have the following shortcode created.
 *     ```
         function add_contestant_function() { 
   
             // Create post object
   
             $num = mt_rand ( 0, 0xffffff ); // created random number
             $idnum = sprintf ( "%06x" , $num ); // formats random number
             $newname = 'PC' . $idnum; // creates new contestant page from random number
             $newpass = 'MMV' . $idnum; // creates new contestant page from random number
             $my_post = array(
               'post_title'    => $newname,
               'post_status'   => 'publish',
               'post_author'   => $newname,
               'post_type'     => 'contestant'
             );
   
             // Insert the post into the database
             wp_insert_post( $my_post );
   
             ob_start();
             ?>
             <p><b>This is your page ID : <?php echo $newname; ?>
             <p>This is your page PASSWORD : <?php echo $newpass; ?></b>
             <?php
             return ob_get_clean();
   
         }
   
         add_shortcode('add_new_contestant', 'add_contestant_function');
       ```
   
 * When it is added to a page it works as expected except that it creates two pages
   every time the page is accessed. I am not sure why. Please tell me what other
   information you may need to help me understand how to fix this.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fshortcode-creating-two-pages%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  [Javier Arce](https://wordpress.org/support/users/javiarce/)
 * (@javiarce)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/shortcode-creating-two-pages/#post-15311510)
 * Hi! I’ve tested your code with a fresh install, and I only got one page on each
   refresh… so maybe the page that contains your shortcode is getting loaded twice?
    -  This reply was modified 4 years, 3 months ago by [Javier Arce](https://wordpress.org/support/users/javiarce/).
 *  Thread Starter [Daddio](https://wordpress.org/support/users/thomasdickerson/)
 * (@thomasdickerson)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/shortcode-creating-two-pages/#post-15311894)
 * We are using a purchased theme, should I contact that coder also.
 *  [Javier Arce](https://wordpress.org/support/users/javiarce/)
 * (@javiarce)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/shortcode-creating-two-pages/#post-15311985)
 * That’s a good idea; maybe they’ll know more about this.
 * Another thing you could do is to check if you have any installed plugins that
   could be causing this reload and disable them momentarily.

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

The topic ‘Shortcode creating two pages’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Javier Arce](https://wordpress.org/support/users/javiarce/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/shortcode-creating-two-pages/#post-15311985)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
