您的部分问题是关于短代码的。这相对简单。
function move_shortcode_to_top($content) {
if (!is_singular()) return;
$regex = get_shortcode_regex();
preg_match_all(\'/\'.$regex.\'/\',$content,$matches);
$move_these = array(
\'testsc\'
);
if (!empty($matches[2])) {
foreach ($matches[2] as $k => $v) {
if (in_array($v,$move_these)) {
$content = $matches[0][$k].str_replace($matches[0][$k],\'\',$content);
}
}
}
return $content;
}
add_action(\'the_content\',\'move_shortcode_to_top\',1);
只需提供一个列表(
$move_these
) 要移动的短代码的。
对于Oembed,您需要一些不同的东西:
function move_oembed_to_top($content) {
$pattern = \'|^\\s*(https?://[^\\s"]+)\\s*$|im\';
preg_match_all($pattern,$content,$matches);
if (!empty($matches[1])) {
$content = preg_replace($pattern,\'\',$content);
$content = implode("\\n",$matches[1])."\\n".$content;
}
return $content;
}
add_filter(\'the_content\',\'move_oembed_to_top\',1);
这将移动尽可能多的嵌入。通过YouTube嵌入测试。
注:That regex is exactly the one used by the Core embed system.