简体   繁体   中英

Manually insert a WordPress plugin inside custom theme's header.php file

All right, so I have an issue I'm trying to work through involving WordPress plugins. I have found a gallery plugin that I like--has pretty much everything I need--but the problem is that placing the shortcode in the content editor causes it to be placed below a banner image that I have (this banner image is stored in my custom theme's header.php file and it has to go there because of the layout of the site I'm working on).

What I want to do is call the plugin inside my header.php before this banner image...but I am having trouble figuring out what I need to do in order to accomplish this. I read about the need to potentially remove the register_activation_hook or activate_pluginname actions when I manually call the plugin in my header.php file...do I need to somehow incorporate these or create functionality similar in my header.php file?

This is what I'm aiming for in my header.php file (I am only looking to load this gallery plugin for the home page, hence the check to see if the page id is the home page id):

  <div id="Container_Body" class="clearfix">
    <div id="topbox">
      <?php 
          $id = get_the_ID();
          $hpid = get_option('page_on_front');
          if($id == $hpid)
          {
            code to display plugin
          }
      ?>
      <div class="GalleryPlugin">
         <?php code to display gallery plugin ?>
      </div>
      <div class="giantBanner" style="background: rgb(0, 141, 175);">
        <img title="Main-Header-Banner" src="<?php bloginfo('template_directory'); ?>/images/Market-Crowd.jpg" alt="Market Crowd">
      </div>
    </div>

Check this

  <?php 

   if(is_home() || is_front_page()) // this will check for homepage its a wp check
   {
        // echo the plugin shortcode here like
       echo do_shortcode('[gallery]');  // this will be any shortcode
   }
   ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM