WordPress.org

Ready to get started?Download WordPress

Forums

WP Super Cache
Dynamic Cached Content in functions.php via add_action (2 posts)

  1. Adam Capriola
    Member
    Posted 3 years ago #

    Hey there,

    I need to tag one small portion of my site as dynamic cached content, similarly as outlined in the code found on the FAQ:

    <!--dynamic-cached-content--><?php
    include_once( ABSPATH . '/scripts/adverts.php' );
    print_sidebar_ad();
    do_more_stuff();
    ?><!--
    include_once( ABSPATH . '/scripts/adverts.php' );
    print_sidebar_ad();
    do_more_stuff();
    --><!--/dynamic-cached-content-->

    However, I am not sure how to do it because the function I need to set as dynamic is in my functions.php file.

    Basically I have a function like this:

    function menu_custom() {
    	global $post, $userdata;
    
    	echo '<div id="menu-custom" class="menu-container">';	
    
    	if ( !is_user_logged_in() ) {
    		echo '<a href="http://www.sixprizes.com/amember/login.php?amember_redirect_url=' . $_SERVER['REQUEST_URI'] . '">Login</a> | <a href="http://www.sixprizes.com/amember/signup.php?price_group=1&product_id=1&hide_paysys=free">Register</a> | <a href="http://www.sixprizes.com/amember/login.php?amember_redirect_url=' . $_SERVER['REQUEST_URI'] . '"><img src="http://www.sixprizes.com/wp-content/uploads/social_facebook_14.png" height="14" width="14" /></a>';
    	}
    
    	elseif ( is_user_logged_in() ) {
    		echo '<a href="http://www.sixprizes.com/amember/member.php">' . $userdata->user_firstname . '</a> | <a href="http://www.sixprizes.com/submit-an-article/">Submit</a> | <a href="http://www.sixprizes.com/forums/">Forums</a> | <a href="http://www.sixprizes.com/category/underground-freebies/">Underground Freebies</a> | <a href="http://www.sixprizes.com/amember/logout.php?amember_redirect_url=' . $_SERVER['REQUEST_URI'] . '">Logout</a> | <a href="http://www.sixprizes.com/amember/member.php?tab=add_renew&price_group=2&product_id=3" class="upgrade">Upgrade</a>';
    	}
    
    	echo '</div>';
    }

    (I simplified it there, but that's basically it.)

    Then I add the function via a hook:

    add_action( 'prototype_before_header', 'menu_custom' );

    And I'm not sure how to apply the example code to this. If I was showing the code in a widget, I know the code would look like this:

    <!--dynamic-cached-content--><?php
    menu_custom();
    ?><!--
    menu_custom();
    --><!--/dynamic-cached-content-->

    But how do I git 'er done when I'm adding the function via add_action?

    Thanks for any help, I really appreciate it!!

  2. Adam Capriola
    Member
    Posted 3 years ago #

    Ok I tried this:

    add_action( 'prototype_before_header', 'dynamic_menu_custom' );
    function dynamic_menu_custom() { ?>
    	<!--dynamic-cached-content--><?php
    	menu_custom();
    	?><!--
    	menu_custom();
    	--><!--/dynamic-cached-content-->
    <?php }
    
    function menu_custom() {
    	echo '<div id="menu-custom" class="menu-container">';
    	if ( !is_user_logged_in() ) {
    		echo 'some stuff';
    	}
    	elseif ( is_user_logged_in() ) {
    		echo 'some other stuff';
    	}
    	echo '</div>';
    }

    And it doesn't seem to work. :(

    EDIT: It works! I needed to enable PHP to serve cache files instead of mod_rewrite. Now I just gotta figure out if things will load faster with PHP serving the cache, or if I should just use Javascript to accomplish the task.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic