在wordporess 中 <iframe>不希望用户通过源代码查看到网址的方法
标签搜索

在wordporess 中 <iframe>不希望用户通过源代码查看到网址的方法

摸鱼仔
2024-05-05 / 0 评论 / 40 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2024年05月04日,已超过137天没有更新,若内容或图片失效,请留言反馈。

在WordPress中,如果您希望在编辑器中插入iframe代码时,不希望用户通过源代码查看到网址,您可以考虑使用插件或者自定义功能来实现这一目的。这可以增加一些安全性,防止用户轻易获取到您的网址信息。

一种方法是创建一个自定义短代码,通过短代码来插入iframe代码,而不是直接在编辑器中粘贴完整的iframe代码。这样可以隐藏实际的网址,用户只能看到短代码的使用方式。以下是一个简单的示例:

一、AIchat嵌入

1、在您的WordPress主题的functions.php文件中添加以下代码:

 /* AIchat嵌入
 */
function custom_iframe_shortcode($atts) {
    return '<iframe style="width: 100%; height: 500px;" src="https://www.***.com" frameborder="0"></iframe>';
}
add_shortcode('custom_iframe', 'custom_iframe_shortcode');

2、然后在WordPress编辑器中使用[custom_iframe]来插入iframe代码。

二、AList嵌入

1、在您的WordPress主题的functions.php文件中添加以下代码:

 /* AList嵌入
 */
function custom_secure_iframe_shortcode($atts) {
    $atts = shortcode_atts(
        array(
            'width' => '100%',
            'height' => '1880',
            'frameborder' => 'no',
            'scrolling' => 'yes'
        ),
        $atts,
        'custom_secure_iframe'
    );

    $iframe = '<iframe src="https://www.***.com" width="' . esc_attr($atts['width']) . '" height="' . esc_attr($atts['height']) . '" frameborder="' . esc_attr($atts['frameborder']) . '" scrolling="' . esc_attr($atts['scrolling']) . '"></iframe>';

    return $iframe;
}
add_shortcode('custom_secure_iframe', 'custom_secure_iframe_shortcode');

2.在文章或页面中使用 [custom_secure_iframe] 短代码即可。

0

评论 (0)

取消