Wordpress’de Özelleştirilmiş Önizleme Linki Nasıl Oluşturulur?

Wordpress üzerinde Gutenberg kullanan benim gibi arkadaşlar kullandıkları preview linkini cache kurallarına göre özelleştirmek isteyebilirler, bu noktada aşağıdaki gibi functions.php dosyasında yapılacak bir değişiklik ile linki istediğiniz şekilde düzenleyebilme imkanınız mümkün

Zaman damgası eklemeyi unutmadık ve gereken kod şu şekilde oldu

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");
        const editorPostSaveDraft = jQuery(".editor-post-save-draft");
        if (editorPostSaveDraft.length && editorPreviewButton.length && editorPreviewButton.attr("href") !== "' . get_preview_post_link() . '&no-cache=' . time() . '" ) {
          editorPreviewButton.attr("href", "' . get_preview_post_link() . '&no-cache=' . time() . '");
          editorPreviewButton.off();
          editorPreviewButton.click(false);
          editorPreviewButton.on("click", function() {
            editorPostSaveDraft.click();
            setTimeout(function() { 
              const win = window.open("' . get_preview_post_link() . '&no-cache=' . time() .'", "_blank");
              if (win) {
                win.focus();
              }
            }, 1000);
          });
        }
      }
    });
  </script>';
}
add_action('admin_footer', 'fix_preview_link_on_draft');

Bundan sonra admin panelinde cache silmeyi unutmayın, daha sonrasında istediğiniz gibi linkleriniz oluşmaya başlayacak.

Sistem Uzmanı, Linux Hacısı, El-Kernel

Yorum yapın