Want to show div on front end wordpress website with wordpress plugin.. If User activate the plugin then div should show on the front side of the wordpress .how to add ? Used add_filter('thecontent') and some more. nothing is working .

Where do you want to place the div? Are you trying to inject the div within the content? If so, you can make a shortcode for this. If you want to inject the div into you could write a plugin with a function to add filter to the content

This function will inject a div above the content output from the editor.

function inject_div( $content )
{
    global $post;

        $html = '<div>'
        $html .= 'Hello World';
        $html .= '</div>'
        $html .= $content;

        return $html;

}
add_filter( 'the_content', 'inject_div' );

This function will add shortcode you can use to insert into post content.

function add_div_shortcode( $atts, $content = null)
{
    extract( shortcode_atts(array('class' => ''), $atts) );

    if($class != ''){
    $class = 'class="'.$class.'"';
    }

    $html = '<div '.$class.'>';
    $html .= $content;
    $html .= '</div>'

    return $html;

}

add_shortcode( 'inject_div', 'add_div_shortcode');

Both of these can be wrapped inside a plugin.

Thanks.. If we want to show div above and below post ..then how will we can do this please tell me..? Tell me with the first function ..not working with shortcode..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.