• CarlosDev

    (@producciones-20)


    Hello WordPress community,
    I’m trying to link a button to the most recent published article, want it to dynamically update the link everytime I publish a new one. The site is using Elementor plugin, is there any way to achieve this with the free version?

    Thanks in advanced.

    • This topic was modified 3 years ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 6 replies - 1 through 6 (of 6 total)
  • Ibrahim Nasir

    (@ibrahimkh4l33l)

    Hello @producciones-20

    I don’t know how this can be done with code. However, you can create a page and add the posts widget, use the full content skin, and limit it to just one post filtered by date.

    You should then disable the page title for that page and voila!

    This is a workaround if you can not find the code that would do this.

    Peace ???

    Thread Starter CarlosDev

    (@producciones-20)

    Thanks for your reply @ibrahimkh4l33l

    Unfortunately, the Elementor posts widget is reserved only for Pro version ??

    I’m testing on this page —> https://carlosmascareno.com/newsite/elementor-306/

    I’m trying with Recent Posts WordPress default widget and HTML code:

    <a class="wp-block-button__link" href="dynamic link here">
    ΜΕΤ?ΦΕΡΕ ΜΕ ΣΤΟ ΠΙΟ ΠΡ?ΣΦΑΤΟ ?ΡΘΡΟ
    </a>
    • This reply was modified 3 years ago by CarlosDev.
    • This reply was modified 3 years ago by CarlosDev.
    • This reply was modified 3 years ago by CarlosDev.
    • This reply was modified 3 years ago by CarlosDev.
    Vijay Hardaha

    (@vijayhardaha)

    You can add a custom function to create a shortcode and then you can return URL or button HTML(based on your need)

    function custom_shortcode_for_last_post_url() {
    	$lastest_post = get_posts(
    		array(
    			'numberposts' => 1,
    			'orderby'     => 'date',
    			'order'       => 'DESC',
    			'fields'      => 'ids',
    		)
    	);
    
    	if ( empty( $lastest_post ) ) {
    		return false;
    	}
    
    	return get_permalink( $lastest_post[0] );
    }
    add_shortcode( 'latest_post_url', 'custom_shortcode_for_last_post_url' );

    you can use shortcode [latest_post_url]

    for HTML

    function custom_shortcode_for_last_post_url() {
    	$lastest_post = get_posts(
    		array(
    			'numberposts' => 1,
    			'orderby'     => 'date',
    			'order'       => 'DESC',
    			'fields'      => 'ids',
    		)
    	);
    
    	if ( empty( $lastest_post ) ) {
    		return false;
    	}
    
    	return '<a href="' . esc_url( get_permalink( $lastest_post[0] ) ) . '" class="">Button Text</a>';
    }
    add_shortcode( 'latest_post_url', 'custom_shortcode_for_last_post_url' );
    Thread Starter CarlosDev

    (@producciones-20)

    I will definitely try that, thank you @vijayhardaha

    I will let you know if that worked.

    Thread Starter CarlosDev

    (@producciones-20)

    You nailed bro! @vijayhardaha
    That did the trick, thank you!

    Vijay Hardaha

    (@vijayhardaha)

    Cheers!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Latest Post Button’ is closed to new replies.