• Resolved maemaemae3

    (@maemaemae3)


    I’m trying to custom preview pages URL, and I was able to change this part of URL by below code.
    https://i.imgur.com/Kjz46J9.png

    
    function replace_preview_post_link ($url) {
      $generate_url = [url_I_want_to_set];
      return $generate_url;
    }
    add_filter('preview_post_link', 'replace_preview_post_link');
    

    but I can’t change URL of part below.
    https://i.imgur.com/Li1KWtb.png

    Does someone know which filter should I set?
    Which part of documentation should I watch to find these information?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter maemaemae3

    (@maemaemae3)

    https://github.com/WordPress/gutenberg/issues/4555#issuecomment-522971630

    looks like it cant… does someone has information about it?

    Thread Starter maemaemae3

    (@maemaemae3)

    I found a temporary solution from here.
    https://github.com/WordPress/gutenberg/issues/13998#issuecomment-568698680

    It didnt work on wordpress 5.6, so I edited a bit.
    This script applys same filter to preview_post_link.

    
    // workaround script until there's an official solution for https://github.com/WordPress/gutenberg/issues/13998
    function fix_preview_link_on_draft() {
    	echo '<script type="text/javascript">
    	jQuery(document).ready(function () {
    		const checkPreviewInterval = setInterval(checkPreview, 1000);
    		function checkPreview() {
    			const editorPreviewButton = jQuery(".edit-post-header-preview__button-external");
    
    			if (editorPreviewButton.length && editorPreviewButton.attr("href") !== "' . get_preview_post_link() . '" ) {
    				editorPreviewButton.attr("href", "' . get_preview_post_link() . '");
    				editorPreviewButton.off();
    				editorPreviewButton.click(false);
    				editorPreviewButton.on("click", function(e) {
    					const editorPostSaveDraft = jQuery(".editor-post-save-draft");
    
    					if(editorPostSaveDraft.length > 0) {
    						editorPostSaveDraft.click();
    					}
    					const intervalId = setInterval(function() {
    						// find out when the post is saved
    						let saved = document.querySelector(".is-saved");
    						if(saved) {
    							clearInterval(intervalId);
    							const win = window.open("' . get_preview_post_link() . '", "_blank");
    							if (win) {
    								win.focus();
    							}
    						}
    					}, 50);
    				});
    			}
    		}
    	});
    	</script>';
    }
    add_action( 'admin_footer-edit.php', 'fix_preview_link_on_draft' ); // Fired on the page with the posts table
    add_action( 'admin_footer-post.php', 'fix_preview_link_on_draft' ); // Fired on post edit page
    add_action( 'admin_footer-post-new.php', 'fix_preview_link_on_draft' ); // Fired on add new post page
    
    • This reply was modified 3 years, 3 months ago by maemaemae3.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to change URL of “Preview in new tab” in gutenberg editor’ is closed to new replies.