• March 22, 2023

    WordPress does not allow you to include PHP code directly into a post. However, you can use a shortcode to include PHP code or call a PHP function in a post.

    Here’s an example of how you can create a shortcode to include a PHP file in a post:

    1. Create a new file in your WordPress theme directory and name it “my_shortcode.php” (or any name you prefer).
    2. Add the PHP code that you want to include in the post in the “my_shortcode.php” file.
    3. Add the following code to your functions.php file:
    codefunction my_shortcode_function() {
       ob_start();
       include 'path/to/my_shortcode.php';
       return ob_get_clean();
    }
    add_shortcode('my_shortcode', 'my_shortcode_function');
    1. Replace ‘path/to/my_shortcode.php’ with the actual path to your “my_shortcode.php” file.
    2. Now, you can use the shortcode [my_shortcode] in your WordPress post to include the PHP code from the “my_shortcode.php” file.

    Note that including PHP code directly in a post can be a security risk, so be sure to only include code that you trust and have verified to be safe.



เวอไนน์ไอคอร์ส

ประหยัดเวลากว่า 100 เท่า!






เวอไนน์เว็บไซต์⚡️
สร้างเว็บไซต์ ดูแลเว็บไซต์

Categories


Uncategorized