Archived topic
Custom link on red more button
23 replies · Started by Carl on December 8, 2022
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/
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.
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!
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.
Thank you! Now it is perfect, thank you!
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.
Did you replace your_custom_field with your custom field name in David's code?
Let us know!
Yes, by search and replace. Thank you.
It seems working fine, the Youtube link goes to the Youtube website.
Are we all good now? Let me know!
