Quantcast
Channel: Topic Tag: plugin | WordPress.org
Viewing all articles
Browse latest Browse all 26892

Jan Dembowski on "Add dynamic content before the loop"

$
0
0

I see only one solution: to tell the user he has to edit the theme code in order to enable the slider where he wants

That's one solution and probably the easiest most reliable way to do it.

Another way to do it is to test if did_action( 'wp_enqueue_scripts' ) fired which would mean the wp_head was done and you're probably in the main loop right after the head.

Give this untested code a look. I had to do something similiar with WP-PageNavi in my theme.

// Insert slider div before the posts but after wp_head
add_action( 'loop_start' , 'mh_main_loop_test' );
function mh_main_loop_test( $query ) {
global $mh_loop_count, $mh_slider_done;
   if ( did_action( 'wp_enqueue_scripts' ) == 1 ) {
      $mh_loop_count++;
      if ( $mh_loop_count == 1 and !$mh_slider_done ) {

		 // Slider div goes here

         $mh_slider_done = true;
      }
   }
}

If wp_enqueue_scripts already fired, $mh_loop_count is 1, and $mh_slider_done is false then you're probably in the loop right after the wp_head above the posts, post titles, content, etc.


Viewing all articles
Browse latest Browse all 26892

Trending Articles