dttwois6098 2019-04-11 11:43
浏览 31

Wordpress:在外部页面中构建短代码内容会导致错误吗?

I'm trying to build my own Wordpress Plugin and right now I'm stuck in creating my shortcode (everything else in the backend works just fine). Basically Im trying to set up the code like:

//Function to display the shortcode
function my_shortcode($atts) {
  include 'my_shortcode_content.php';
} 

As you can see I am trying to just simply include the content from an external php file and not write it directly into the function.

The my_shortcode_content.php looks like this:

<?php
    global $wpdb;

    $table_name = $wpdb->prefix . "test";
    $table_name_categories = $wpdb->prefix . "test_categories";
    $stuff = $wpdb->get_results("SELECT * FROM ".$table_name);
    $categories = $wpdb->get_results("SELECT * FROM ".$table_name_categories);

    echo "<div>Test</div>";
?>

Now the problem is that when I try to echo my HTML Code or even try to put the raw HTML Code outside the -tag I cannot edit my page anymore.

Everytime I try to edit the page in wordpress (where I have my shortcode implemented in a simple text field) and hit save, it only tells me that the update failed and the changes I made in my page are not saved. Now the weird thing is, if I add stuff to my shortcode content file it will display the change on the page, but if I want to remove / edit something else that is not my shortcode, I simply can't because it throws me an error. BUT if I remove the HTML Code from my shortcode content page, everything works just fine and I can edit my page again.

Does anyone know how what could cause this problem?

Btw I'm using docker-wordpress to test my stuff, tho I do not think that this could cause the error.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大