- This topic has 23 replies, 4 voices, and was last updated 3 years, 3 months ago by
Ying.
-
AuthorPosts
-
December 23, 2022 at 12:59 pm #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/December 24, 2022 at 4:57 am #2472239David
StaffCustomer SupportIf 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 toPost Metaand in the filed provided add your custom field name.December 24, 2022 at 5:29 am #2472262Carl
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!
December 24, 2022 at 7:29 am #2472352David
StaffCustomer SupportSO 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.December 27, 2022 at 5:28 am #2474599Carl
Thank you! Now it is perfect, thank you!
December 27, 2022 at 9:45 am #2474926Carl
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.December 27, 2022 at 1:08 pm #2475053Ying
StaffCustomer SupportDid you replace
your_custom_fieldwith your custom field name in David’s code?Let us know!
December 27, 2022 at 1:42 pm #2475089Carl
Yes, by search and replace. Thank you.
December 28, 2022 at 12:37 pm #2476107Ying
StaffCustomer SupportIt seems working fine, the Youtube link goes to the Youtube website.
Are we all good now? Let me know!
-
AuthorPosts
- You must be logged in to reply to this topic.