Forums

WP Super Cache
WP Super Cache Plugin ShortCode mfunc (12 posts)

  1. yannou974
    Member
    Posted 11 months ago #

    Hi,
    2 days i'm trying to use mfunc without success.

    I'm using it inside my plugin developpement.

    I'm using shortcode to make it appear in user-view.

    Here is my code:

    <?php
    function XXX_get($atts, $content = null) {
    			?>
    
    <!--MFUNC return rand() -->
    <?php return rand(); ?>
    <!--/mfunc -->
    
    <?php
    }
    
    add_shortcode('XXX', 'XXX_get');
    ?>

    My problem is, it returns always the same number.
    Never different.

    Where is my problem ?

    Thanks

  2. Donncha O Caoimh
    Member
    Posted 11 months ago #

    Make MFUNC lowercase?

  3. yannou974
    Member
    Posted 11 months ago #

    already tried, but no :(

  4. Olaf
    Member
    Posted 4 months ago #

    Hi Donnacha,
    I try to the same:
    I'm using a shortcode to show adsense on specific positions in my posts. To protect my adsense account for getting "smart priced" I like to hide the ads for a few countries. I use this code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I don't get an error, but the ad content is still cached.
    Is it possible to do this using short codes?

    Thanks!
    `

  5. Donncha O Caoimh
    Member
    Posted 4 months ago #

    Take a look at the cached file in your cache directory and see what code it contains. Then load up wp-cache-phase1.php and trace what happens there. Look for "eval" which is the command that runs the cached file.

  6. Olaf
    Member
    Posted 4 months ago #

    Thanks Donncha,

    do you got the chance to see my code?
    You say that it has to be possible to use shortcodes for dynamic content parts?

  7. Donncha O Caoimh
    Member
    Posted 4 months ago #

    Olaf - I didn't see it. Can you use a pastebin?

  8. Olaf
    Member
    Posted 4 months ago #

    sure here it is:

    http://pastebin.com/PdYTZTha

  9. Donncha O Caoimh
    Member
    Posted 4 months ago #

    What happens if you put the mfunc code directly in your theme? Or use a filter to filter the posts and insert the mfunc chunk of code that way?

    I think the issue is that the mfunc string isn't getting cached because the shortcode function "returns" the code output. You should probably return "<!--mfunc echo get_adsense() -->" etc, and not just return the output of get_adsense().

  10. Olaf
    Member
    Posted 4 months ago #

    That's what I thought first how this works :)
    I will try this, thanks

  11. Olaf
    Member
    Posted 4 months ago #

    Donncha, using "echo" instead of "return" was the solution (time to write a tutorial about)

    Thanks a lot!

  12. Olaf
    Member
    Posted 4 months ago #

    Donncha, there is one tiny problem.
    If I place the shortcode inside the theme using do_shortcode it's fine, but if I have the shortcode inside an article the generated code get moved to the begin of the content. I think it happens because I'm using the "echo" instead of the "return". Any idea?

    EDIT: looks like I was in trouble with my browser cache yesterday, it works with the code I posted @pastebin

Reply

You must log in to post.

About this Plugin

About this Topic