Home › Forums › Pro Support › Manual title is below excerpt
- This topic has 5 replies, 2 voices, and was last updated 2 years, 6 months ago by
elvin.
-
AuthorPosts
-
March 25, 2021 at 11:29 am #28506
Bernhard
ParticipantMarch 25, 2021 at 5:01 pm #28526elvin
ModeratorHi there,
Your add_action snippets don’t have priority values set to them so whoever was added first goes before the other one.
But we should be able to control this:
You have this code for excerpt:
//Use excerpt as title WPSP add_action( 'wpsp_after_content', function( $settings ) { if ( 32293 === $settings['list_id'] ) { echo '<h2>'; the_excerpt(); echo '</h2>'; } } );
add
,5
after the}
So it’ll look like this:
//Use excerpt as title WPSP add_action( 'wpsp_after_content', function( $settings ) { if ( 32293 === $settings['list_id'] ) { echo '<h2>'; the_excerpt(); echo '</h2>'; } }, 5 );
For the title, if you want it to go ABOVE the excerpt, add a priority value lower than 5.
Like this:
add_action( 'wpsp_after_content', function( $settings ) { if ( 123 === $settings['list_id'] ) { echo '<h2>'; echo get_the_excerpt(); echo '</h2?'; } }, 1 );
if you want it to go BELOW the except, add a priority value higher than 5.
Like this:
add_action( 'wpsp_after_content', function( $settings ) { if ( 123 === $settings['list_id'] ) { echo '<h2>'; echo get_the_excerpt(); echo '</h2?'; } }, 10 );
Make sure to pay attention to
add_action()
‘s priority value. It’s good practice to always add one.Reference: https://developer.wordpress.org/reference/functions/add_action/
March 26, 2021 at 6:42 am #28567Bernhard
ParticipantHi Elvin,
my excuses, I linked to the wrong reply in the thread.Actually the excerpt is triggered by WPSP without additional code and the title is called from the custom field
wpsp_title2
with this code.Adding the priority value to the title, it would look like this
add_action( 'wpsp_after_content', function( $settings ) { $custom_field = get_post_meta( get_the_ID(), 'wpsp_title2', true ); if ( $custom_field && 32293 === $settings['list_id'] ) { echo '<h2>'; echo $custom_field; echo '</h2>'; } }, 1 );
but i don’t know how to trigger the excerpt priority in WPSP.
March 29, 2021 at 12:10 am #28640elvin
ModeratorI’m not sure I understand what you mean.
To clarify: If you’re saying you want to move the default excerpt being displayed by WPSP, there’s no way to do that w/o editing the plugin as it’s hard coded.
If you want your code to appear before the default excerpt, you should change the hook you’re using from
wpsp_after_content
towpsp_before_content
as this hook appears before the default excerpt as shown here: https://github.com/tomusborne/wp-show-posts/blob/35e410d7800273fc66f211c0f80d553e95d17f83/wp-show-posts.php#L460You can see here that the default excerpt is hardcoded and comes 8 lines after
wpsp_before_content
.March 29, 2021 at 4:40 am #28654Bernhard
ParticipantPerfect, thank you 🙂
March 29, 2021 at 10:43 pm #28666elvin
ModeratorNo problem. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.