• Hi Guys,

    I am in the process of producing a custom theme for a client.

    The theme’s homepage will have a Jetpack tiled Gallery displaying full width across the page…BEFORE THE CONTENT.

    The client wants to be able to edit the content of the gallery when the see fit.

    I thought that the process of placing the gallery shortcode in my template would work via echo do shortcode. But what I need to do is take it out of the_content(); and display just before the content begins.

    How can I achieve this???

    Here is the code for this particular part including the html so you awesome wordpress dudes can help me out.

    <section class="row main-content-home" role="main">
    
    <?php if (have_posts()): while (have_posts()) : the_post(); ?>
    
    <div class="gallery-display">
    	I WANT TO PLACE THE GALLERY HERE, BUT I CAN'T JUST PUT IN THE ID'S BECAUSE THEY MIGHT CHANGE. I NEED A DYNAMIC APPROACH.
    </div>
    
    <div class="container">
        <h1><?php the_title(); ?></h1>
          <?php the_content(); ?>
    
    //REST OF THE LOOP
    </div>
    </section>

    If somebody could help me it would be great.

    Dan

Viewing 5 replies - 1 through 5 (of 5 total)
  • Have you considered using a custom field for this?
    Or perhaps even some kind of post relationship, where the related post has a specific tag.

    Some tools that could be leveraged to help you achieve this could be Pods, CMB2, or Advanced Custom Fields, or Fieldmanager (to name a few).

    For example, you could create a new WYSIWYG field that’s specifically to be output above the normal content.

    Thread Starter 83creative

    (@winnard)

    Hi Richard,

    Thanks for getting back to me. I currently use a plugin called “Multiple Content Blocks” which is perfect for what I need. I just rely on that plugin quite a bit and wondered if there was a way I could learn to code it without using a plugin.

    I didn’t think about the Advanced Custom Fields plugin so I may look into that. I know the saying “why re-invent the wheel” but I want to try and learn for myself and not rely on so much plugin functionality.

    I will wait it out for an answer and in the meantime use the plugin to solve the issue.
    ??

    Okay, you want to avoid a plugin, and look at how to do it from scratch yourself.

    We still have options, so let’s consider an alternative approach.

    One potential solution is to check the content of a page/post for the WordPress Gallery Shortcode with the get_post_gallery function. If the shortcode exists in the content, we could output it wherever we want on the template (example for output is included in that same link).

    We could then remove the first gallery shortcode from the content itself in a function hooked to the_content filter later.

    Hi winnard,

    If I understood everything that you stated earlier correctly, then I believe this proof of concept would be something that you could use and adapt to your particular use case.

    https://gist.github.com/richaber/8bd66b46e07ffef0635a

    The front-page.php template echos get_post_gallery outside of the_content.

    The function and filter in functions.php then removes that first gallery shortcode from the_content when the_content is being output in the front-page.php template.

    This might not be exactly what you were looking for, but hopefully it gives you some ideas and helps you find what you’re looking for.

    Thread Starter 83creative

    (@winnard)

    Hi Richaber

    I cannot thank you enough for spending the time to find all this useful information.

    I will definitely have a play with what you have supplied. Having briefly looked through the code, I will only ever be pulling out the gallery on the homepage of the website so it looks like it could be a good fit.

    Many thanks again for your help. I will let you know how I got on with it before marking this thread as resolved.

    Dan

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Gallery Shortcode custom placement’ is closed to new replies.