首页 > 解决方案 > 围绕块元素进行锚链接时的Wordpress奇怪行为

问题描述

在 wordpress html 编辑器中,我添加

<a href="/s/toto"><div><img src="/wp-content/uploads/toto.jpg" width="4" height="4"><h2>toto</h2></div></a>

保存时,它变成(最后创建空链接):

<a href="/s/toto">
<div><img src="/wp-content/uploads/toto.jpg" width="4" height="4">
<h2>toto</h2>
</div>
</a><a href="/s/toto"></a>

我尝试过的但在我的情况下不起作用:添加functions.php

remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' );

或者

add_filter('tiny_mce_before_init', 'modify_valid_children', 99);
function modify_valid_children($settings){     
    $settings['valid_children']="+a[div|p|ul|ol|li|h1|span|h2|h3|h4|h5|h5|h6]";
    return $settings;
}

标签: wordpresshyperlinkblock

解决方案


推荐阅读