Support » Fixing WordPress » Changing the “View page” link

  • Hi WordPress enthusiasts!

    We’re creating a headless website where WordPress is used as backend, and the frontend is made in ReactJS. Works out really well – it’s amazing how you can “twist and bend” WordPress to make it work with a ReactJS frontend.

    Now, we’re in the last phase. The client is asking if we can change the “View Page” URL when you’re editing a page or post. We need this because the backend is running on “api.website.com” – and the frontend is on “website.com”.

    So, if we were to use the standard link, it would redirect us to the api-website, and not the frontend. I hope this makes sense.

    I’m sure there is a filter, which i have overseen.

    Thanks a lot!

    Best regards
    Aris Kuckovic

Viewing 6 replies - 1 through 6 (of 6 total)
  • @kuckovic could you attach screenshots?

    Thread Starter kuckovic

    (@kuckovic)

    Hi @aamirkhatri

    Here’s a screenshot: https://imgur.com/LiuC9Bi

    I’m working with the exact same setup and ran into the same problem. I ended up using the page_link and post_link filters to replace the URL. Which seems to work fine for normal posts and pages.

    function custom_frontend_url( $permalink, $post ) { 
    	$custom_permalink = str_replace( home_url(), 'https://yourwebsite.com',  $permalink );
    
    	return $custom_permalink; 
    }; 
    			
    add_filter( 'page_link', 'custom_frontend_url', 10, 2 ); 
    add_filter( 'post_link', 'custom_frontend_url', 10, 2 );
    // If you use custom post types also add this filter.
    add_filter( 'post_type_link', 'custom_frontend_url', 10, 2 ); 
    Thread Starter kuckovic

    (@kuckovic)

    @sjoerdkoelewijn

    Sorry for my late reply – I have a pregnant wife, who needs some attention 😛
    I will definitely give this a try – and as I can see, it should work!

    May I ask – what have you done regarding “preview”?
    I’ve created a special function to retrieve the “preview-post” from the DB – and resets on page-reload of course – but I’m curious about what others have done?

    Best regards
    Aris Kuckovic

    That’s still on my to-do list 🙂 I think this would work for me, as I’m using Gatsby https://justinwhall.com/live-previews-with-wordpress-gatsby/ but I haven’t actually looked at it yet.

    Thread Starter kuckovic

    (@kuckovic)

    @sjoerdkoelewijn

    Ah okay.
    Mine is working perfectly fine now – so there IS a way to do it 😀
    And nice to hear that you’re using Gatsby 😀

    Our own website is running on Netlify – we have some issues tho – but it’s going to be fixed. Cool to hear what others do 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Changing the “View page” link’ is closed to new replies.