We're merging with GenerateBlocks! Learn more here.

[Resolved] Excerpt as title

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Excerpt as title

Viewing 15 posts - 1 through 15 (of 24 total)
  • Author
    Posts
  • #16642
    Bernhard
    Participant

    Hello,
    in some of my cards I use an excerpt of the first paragraph with a defined number of words.

    Now I have a particular problem. I want to use in some cases cards as title h2, but not the “long” post title. It shall be a “short title” defined e.g. in the manual excerpt field (or in another custom field).

    Is this possible?

    Thank you

    #16672
    Tom
    Keymaster

    Hi there,

    I’m not sure I fully understand – can you explain a bit more?

    #16680
    Bernhard
    Participant

    Hi Tom,
    on my new designed homepage the table of content links to cards “overlay” style which show only the page/post title with h2. Sample link

    This is fine for this page.

    Now I’m developing another new page, where I don’t want to have the full page or post title in cards but a manually defined title which I insert, maybe, in the excerpt field (I have it already there in pages and posts). I use the manual excerpt nowhere else.

    So my idea is to pick up the text of the excerpt field and show it as title h2. Would it be possible to insert a “use excerpt as title” checkbox?

    Otherwhise would it be possible to hardcode it in the way that, if the “include title” is unchecked it uses the excerpt as title h2 with a font height to be defined?

    Thank you

    #16737
    Tom
    Keymaster

    Hmm, tricky.

    I suppose you could disable the title, then do this:

    add_action( 'wpsp_after_content', function( $settings ) {
        if ( 123 === $settings['list_id'] ) {
            echo '<h2>';
                echo get_the_excerpt();
            echo '</h2?';
        }
    } );
    #16757
    Bernhard
    Participant

    Hi Tom,
    the result is strange, you can see it here. In the Elementor preview I see the standard H2 title size + ►►► (see screenshot above), on the page I see normal text color white with ►►►.
    The arrows are coded because WPSP is not compatible with Polylang for the read more function.

    The full code related to WPSP is

    //Disable read more tag in wpsp
    add_filter( 'wpsp_more_tag', '__return_empty_string' );
    
    //Disable image title on hover in wpsp
    add_filter( 'wpsp_image_title', '__return_empty_string' );
    
    // Read more function in WPSP
    add_filter( 'wpsp_ellipses', function() {
        return sprintf( 
            '...<a href="%1$s">&ensp;►►►</a>',
            get_permalink()
        );
    } );
    
    add_filter( 'get_the_excerpt', function( $excerpt ) {
        if ( has_excerpt( get_the_ID() ) ) {
            $excerpt .= sprintf( 
                '...<a href="%1$s">&ensp;►►►</a>',
                get_permalink()
            );
        }
        return $excerpt;
    } );
    
    //Use excerpt as title WPSP
    add_action( 'wpsp_after_content', function( $settings ) {
        if ( 32293 === $settings['list_id'] ) {
            echo '<h2>';
                the_excerpt();
            echo '</h2>';
        }
    } );
    #16759
    Bernhard
    Participant

    I forgot

    
    // WPSP show excerpt field on pages
    add_action( 'wpsp_before_content', function( $settings ) {
        $meta = get_post_meta( get_the_ID(), '_your_custom_meta_key', true );
    
        if ( isset( $meta ) && '' !== $meta && 23138 == $settings['list_id'] ) {
            echo $meta;
        }
    } );
    #16804
    Tom
    Keymaster
    #16817
    Bernhard
    Participant

    OK, how can I handle the colour and the size?

    #16821
    Tom
    Keymaster

    You will likely need to use CSS like this:

    .wpsp-content-wrap h2 {
        /* your CSS here */
    }
    #16841
    Bernhard
    Participant

    Perfect.

    Is it possible to have more ID’s in one action or must I repeat the full code for every ID?
    Can I insert the action into an Elements hook or works it only in the functions.php?

    #16846
    Bernhard
    Participant

    One mor thing: the manual excerpt shall not substitute the automatic excerpt on the blog pages and not in the normal lists. Basically, the manual excerpt shall only be shown in the lists addressed directly with the action above.

    #16853
    Tom
    Keymaster

    Hi there,

    You can use Elements if you want to hook it into every single list, just add the hook name into the Custom Hook field.

    #16874
    Bernhard
    Participant

    OK. I see that the use of the excerpt field is not practical for me. How can I address a custom field as title, e.g. wpsp_title2

    #16897
    Tom
    Keymaster

    You’d do 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>';
        }
    } );
    #16909
    Bernhard
    Participant

    Perfect.

    A question about the use of Elements: You wrote

    just add the hook name into the Custom Hook field

    I don’t understand what to use as hook name.

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