Site logo

Archived topic

Excerpt Action Hook

38 replies · Started by Andy on June 2, 2019

Viewing posts 1–15 of 39

Hi,
Is there any way of inserting an opening/closing shortcode tag before/after the excerpt shown on archive pages? - perhaps with some kind of hook?. Would also need to do the same for WP Show Posts lists.

Hi there,

Not exactly sure what you are trying to do but I don't believe so.

The excerpt for GP and WP Show Posts is actually handled by Wordpress' core function.

You can learn more about it here with lots of examples towards the bottom of the page:
https://developer.wordpress.org/reference/functions/the_excerpt/

You can check it out in action here:
https://github.com/tomusborne/generatepress/blob/6933da4f9a85e183bcf8485836339043dfc4a650/content.php

Hope this helps :)

Basically I want to put the excerpt inside an accordion/expander.

Hi there,

Instead of placing the excerpt inside a toggle we could do this:

1. Create a new hook element
1.1 Add this markup to create a toggle 'button':

<span class="accordion-toggle">toggle</span>

1.2 Select the after_entry_header hook
1.3 Set you display rules to blog and archive

2. Create a second hook for our our jQuery:

<script type="text/javascript">
  jQuery(document).ready(function($) {
    $('.accordion-toggle').click(function(){

      //Expand or collapse this panel
      $(this).next().slideToggle('fast');
      
      //Hide the other panels
      $(".accordion-content").not($(this).next()).slideUp('fast');
      
      //Switch toggle
      $('.accordion-toggle.toggle-open').not(this).removeClass('toggle-open');
      $(this).toggleClass('toggle-open');
    });
  });
</script>

2.1 Select the WP_footer hook
2.2 Set the display rules the same as first hook.

3. Add this CSS to hide the Excerpt when page is first loaded:

.entry-summary {
	display: none;
}

You then just need to edit your original span for the toggle text / icon you want. When its open the toggle span will get the toggle-open class so you can style it differently.

Thank you David this is working brilliantly on the Blog/Category Archive pages. Any way to get it working on WP Show Posts lists too?

Awesome :)
so create another hook like the first one. This time select the Custom Hook in the hook list and in the field provided add: wpsp_after_title and set your display rules to cover any of the pages where WPSP is being used.

ok I have the toggle displaying but it's above the wp-show-posts-entry-summary html so doesn't contain the excerpt.

Here's the main hooks you can add content to in WPSP:

wpsp_before_wrapper
wpsp_before_header
wpsp_before_title
wpsp_after_title
wpsp_before_content
wpsp_after_content
wpsp_after_wrapper

Maybe try the wpsp_before_content - if not i would need to see the site.

Thanks David, I tried wpsp_before_content and it works but the toggle is open on page load, I'd want it closed.

Silly me, all I had to do was add the WP Show Posts html to the display:none rule, .wp-show-posts-entry-summary.

Thank you very much David it works really well.

I've also learnt how to use the custom hooks feature which would seem to add even more power/customization options, as I believe it will allow you to use any hook from any plugin you have installed?.

Aah my bad, yes the CSS needed updating
That's really cool - i like these sorts of ideas. May borrow that for another Site :)

Yes Custom Hooks any hook that is available for adding content can be used.

Just thought I'd mention it doesn't work when using Infinite Scroll. I had a feeling that would be the case as I was already using another hook below the title for another plugin and that doesn't work with infinite scroll either. The plugin developer said it's on his to-do list but isn't an easy fix, so for the time being perhaps I will disable Infinite Scroll and just use normal pagination.

Hmmm... i'll take a look, thanks for reporting.

Just wondering if you had any time to look into this yet?

I think the issue is the jQuery isn't being triggered in thee WP_Footer due to the infinite scroll. Nots sure though. Can you try moving it to the WP_head.

This archived topic is closed to new replies.