We're merging with GenerateBlocks! Learn more here.

[Resolved] Manual title is below excerpt

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Manual title is below excerpt

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #28506
    Bernhard
    Participant

    Hello,
    Tom explained me here how to insert a manual title. Now I want to add a manual excerpt but it is shown above the title. Please see the sample, the excerpt is white, the title dark red. The first card is polaroid, the 2nd and 3rd are overlay cards.

    #28526
    elvin
    Moderator

    Hi 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/

    #28567
    Bernhard
    Participant

    Hi 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.

    #28640
    elvin
    Moderator

    I’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 to wpsp_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#L460

    You can see here that the default excerpt is hardcoded and comes 8 lines after wpsp_before_content.

    #28654
    Bernhard
    Participant

    Perfect, thank you 🙂

    #28666
    elvin
    Moderator

    No problem. 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.