Site logo

[Resolved] Custom link on red more button

Home Forums Support [Resolved] Custom link on red more button

Home Forums Support Custom link on red more button

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #2471886
    Carl

    Wow, your script does ecact, what I´ve expected, I´m happy!
    But one thing: I´m not able to activate the read more button via the customizer.
    I have deleted evrything in the css that could hide this button.

    I only can create a read more button from Fernandos tutorial as a hook.
    But if I put in there the link-field, the normal post has no link and the button do not run.

    Witch variable I could insert there?
    https://www.denkanstösse-limburgerhof.info/akt/

    #2472239
    David
    Staff
    Customer Support

    If you want to use the hooked in button, then:

    1. select the button block in your hook.
    2. enable its Dynamic data in the sidebar settings, and set the Link Source to Post Meta and in the filed provided add your custom field name.

    #2472262
    Carl

    Thank you for answering my questions even on Christmas Eve!
    That’s exactly what I did. Only if it is a simple post, I have not entered a URL in this field.
    With the link on the picture and the headline, the normal post opens, not on the read more button.

    Kind Regards!

    #2472352
    David
    Staff
    Customer Support

    SO instead of hooking in a button, create a custom shortcode:

    add_shortcode('custom_read_more', function(){
        $has_url = get_post_meta(get_the_ID(), 'your_custom_field', true);
        $url = ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
        return sprintf(
            ' ... <a title="%1$s" class="read-more" href="%2$s" aria-label="%4$s">%3$s</a>',
            the_title_attribute( 'echo=0' ),
            esc_url( $url ),
            __( 'Read more', 'generatepress' ),
            sprintf(
                /* translators: Aria-label describing the read more button */
                _x( 'More on %s', 'more on post title', 'generatepress' ),
                the_title_attribute( 'echo=0' )
            )
        );
    });

    Then you can add the [custom_read_more] shortcode to your hook.
    It should display the custom field if available, if not it will return the post url.

    #2474599
    Carl

    Thank you! Now it is perfect, thank you!

    #2474926
    Carl

    I don’t know if I missed it or what happened, but now the title link only goes to the post link and not the custom link.
    The other two works fine.

    #2475053
    Ying
    Staff
    Customer Support

    Did you replace your_custom_field with your custom field name in David’s code?

    Let us know!

    #2475089
    Carl

    Yes, by search and replace. Thank you.

    #2476107
    Ying
    Staff
    Customer Support

    It seems working fine, the Youtube link goes to the Youtube website.

    Are we all good now? Let me know!

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