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

Member

by deron , in category: PHP General , a year ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , a year 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 .

Related Threads:

How to return a value from a function in PHP?
How to display html output from php return function?
How to access to php function on wordpress?
How to format date and time in php function in wordpress?
How to delete/hide div class in wordpress?
How to return function result in graphql?