【问题标题】:How can i remove pages generated from image attachments on wordpress?如何删除从 wordpress 上的图像附件生成的页面?
【发布时间】:2019-06-13 22:17:21
【问题描述】:

图片附件页面显示在网站的搜索结果中。我需要知道如何删除当前存在的那些。如果我只能在我的数据库中执行此操作,我如何确保删除实际的附件页面而不是原始页面本身。

here is where the problem is

【问题讨论】:

    标签: database wordpress phpmyadmin


    【解决方案1】:

    如果您已安装 Yoast SEO,您可以禁用媒体附件页面。或者你可以将它粘贴到你的functions.php

    function myprefix_redirect_attachment_page() {
    if ( is_attachment() ) {
        global $post;
        if ( $post && $post->post_parent ) {
            wp_redirect( esc_url( get_permalink( $post->post_parent ) ), 301 );
            exit;
        } else {
            wp_redirect( esc_url( home_url( '/' ) ), 301 );
            exit;
        }
      }
    }
    add_action( 'template_redirect', 'myprefix_redirect_attachment_page' );
    

    【讨论】:

      【解决方案2】:

      你可以使用这个小sn-p - 将它添加到你的子主题的functions.php中:

      function remove_attachments_from_search() {
          global $wp_post_types;
          $wp_post_types['attachment']->exclude_from_search = true;
      }
      add_action('init', 'remove_attachments_from_search');
      

      这将从搜索结果中排除附件帖子类型。

      希望对你有帮助

      【讨论】:

      • 感谢您的 sn-p。不幸的是,它仍然不起作用。不知何故,图片附件仍然出现在搜索结果中。
      猜你喜欢
      • 1970-01-01
      • 2019-08-21
      • 2013-11-24
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多