0

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 .

2
Contributors
2
Replies
22
Views
3 Years
Discussion Span
Last Post by mwnt2014
0

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.

0

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..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.