How to return <div> in wordpress function php file?

Member

by deron , in category: PHP General , 2 months ago

How to return <div> in wordpress function php file?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , 2 months ago

@deron 

To return a in a WordPress function PHP file, you can use the built-in WordPress function get_the_excerpt(). Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function custom_div() {
    ob_start(); // Start output buffering

    // Get the content within <div>
    echo '<div>';
    echo get_the_excerpt(); // Replace get_the_excerpt() with your desired content
    echo '</div>';

    $content = ob_get_clean(); // Get the buffered content

    return $content; // Return the content within <div>
}


This function will return the content within a tag. You can replace get_the_excerpt() with any content that you want to display within the .