• Resolved lexa1

    (@lexa1)


    I saw that after activating AIOS plugin when opening page, script is triggered twice. To test it, I made a simple shortcode.

    function my_test_shortcode_fun() {
    $post_id = get_the_ID();
    $loads = get_post_meta( $post_id, 'load_1', true );
    if($loads==1){
    $load_txt='Is Load 2';
    update_post_meta($post_id , 'load_2', 2);
    }else{
    $load_txt='Is Load 1';
    update_post_meta($post_id , 'load_1', 1);
    }
    return  $load_txt;
    }
    add_shortcode('my_test_shortcode', 'my_test_shortcode_fun');

    After opening the page once, two custom fields will be created. From this you can see that shortcode is triggered twice. If you deactivate AIOS plugin, then when the page is opened once, only one field is created, as it should be. How do I fix this double triggering?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author arnaudbroes

    (@arnaudbroes)

    @lexa1 AIOSEO runs shortcodes when we’re autogenerating the title and description. We have to do this because we otherwise cannot generate a decent title/description if the page is built with a page builder plugin.

    The easiest way to work around this to either add caching to your callback method by doing something like this –

    static $count = 0;
    $count++;
    if ( $count > 1 ) {
    	return;
    }

    By doing, the code should return early on the second run.

    Thread Starter lexa1

    (@lexa1)

    Where exactly should I put this code?

    Plugin Author arnaudbroes

    (@arnaudbroes)

    At the top of the callback function. But it depends on what you’re trying to do.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Double page load’ is closed to new replies.