admin管理员组文章数量:1134556
I have a custom block which I've created with the following code:
<?php include get_template_directory() . '/template-parts/blocks/form/from/functions.php';
if(!isset($_POST['firstFormDisplayed'])) {
// we haven't yet displayed the form asking for numbers, so do that now.
displayFirstForm();
} else {
// we've got the numbers, but not the details, so do that now!
displaySecondForm();
} ?>
I have this added to a page and that page allows me to edit it with no problems. If I edit it as a Post, it's showing an error:
Fatal error: Cannot redeclare displayFirstForm() (previously declared in
/public_html/wp-content/themes/my-theme/template-parts/blocks/form/from/functions.php:5) in
/public_html/wp-content/themes/my-theme/template-parts/blocks/form/from/functions.php on line 5
I don't need to edit this block in the WordPress editor, I've tried adding a "is_admin()" but it's still showing as an error.
Line 5 in functions.php is:
function displayFirstForm()
I have a custom block which I've created with the following code:
<?php include get_template_directory() . '/template-parts/blocks/form/from/functions.php';
if(!isset($_POST['firstFormDisplayed'])) {
// we haven't yet displayed the form asking for numbers, so do that now.
displayFirstForm();
} else {
// we've got the numbers, but not the details, so do that now!
displaySecondForm();
} ?>
I have this added to a page and that page allows me to edit it with no problems. If I edit it as a Post, it's showing an error:
Fatal error: Cannot redeclare displayFirstForm() (previously declared in
/public_html/wp-content/themes/my-theme/template-parts/blocks/form/from/functions.php:5) in
/public_html/wp-content/themes/my-theme/template-parts/blocks/form/from/functions.php on line 5
I don't need to edit this block in the WordPress editor, I've tried adding a "is_admin()" but it's still showing as an error.
Line 5 in functions.php is:
function displayFirstForm()
Share
Improve this question
asked Aug 10, 2023 at 10:27
RustyInglesRustyIngles
1133 bronze badges
1 Answer
Reset to default 1This should work:
<?php
if ( is_user_logged_in() ) {
echo "This isn't editable in here";
} else {
include get_template_directory() . '/template-parts/blocks/form/from/functions.php';
if ( ! isset( $_POST['firstFormDisplayed'] ) ) {
// we haven't yet displayed the form asking for numbers, so do that now.
displayFirstForm();
} else {
// we've got the numbers, but not the details, so do that now!
displaySecondForm();
}
}
?>
本文标签: WordPress custom Block showing error in Posts editor but working in Pages editor
版权声明:本文标题:WordPress custom Block showing error in Posts editor but working in Pages editor 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736837887a1954968.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论