如何自动将PHP包含在WordPress摘录中


How do I automatically include PHP in Wordpress excerpt?

如何在我的WordPress帖子中自动包含以下PHP脚本?

<?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>

我不熟悉PHP,我假设以上是我用来显示社交共享按钮的插件的代码。

我希望有人之前可能已经处理过自动将元素添加到摘录中,并且会有一些代码可以复制到我的子主题中functions.php

AddToAny Share Buttons插件

都有选项Display at the bottom of excerpts或者您可以添加代码

function add_excerpt_social( $excerpt ) {
    if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { return $excerpt.ADDTOANY_SHARE_SAVE_KIT(array("output_later" => true)); }
    else { return $excerpt; }
}
add_filter('get_the_excerpt', 'add_excerpt_social');

到您的主题functions.php文件。