How do wordpress plugins add content?

This may be a weird question. When I add plugins like the Facebook Like Button and Gigpress, they offer options to insert content before or after each single-page blog post. For example, I have both Gigpress and the FB Like button set to add content below the text in my posts, and that is working, be it imperfectly. The like button shows up below the post text.

So how is this accomplished on the back end? It doesn’t look like the templates or other php files are being altered by the plugins, but there also doesn’t seem to be any obvious php code that would be pulling in the data. Is this type of functionality somehow built into the “framework”?

Read More

The reason I’m asking is for formatting reasons…the content that is added by the two plugins conflicts and looks bad. I’m trying to figure out how to modify the css.

Thanks

Related posts

Leave a Reply

1 comment

  1. They are achieving it with Filters, Actions and Hooking into them.

    In your case – with the_content filter ..

    Example ( from codex ) :

    add_filter( 'the_content', 'my_the_content_filter', 20 );
    /**
     * Add a icon to the beginning of every post page.
     *
     * @uses is_single()
     */
    function my_the_content_filter( $content ) {
    
        if ( is_single() )
            // Add image to the beginning of each page
            $content = sprintf(
                '<img class="post-icon" src="%s/images/post_icon.png" alt="Post icon" title=""/>%s',
                get_bloginfo( 'stylesheet_directory' ),
                $content
            );
    
        // Returns the content.
        return $content;
    }
    

    A simpler to understand example :

     add_filter( 'the_content', 'add_something_to_content_filter', 20 );
    
    
     function add_something_to_content_filter( $content ) {
    
                $original_content = $content ; // preserve the original ...
                $add_before_content =  ' This will be added before the content.. ' ;
                $add_after_content =  ' This will be added after the content.. ' ;
                $content = $add_before_content . $original_content  . $add_after_content ;
    
            // Returns the content.
            return $content;
        }
    

    to see this example in action , put it in your functions.php

    This is actually the single most important step to understanding wordpress, and starting to write plugins. If you really are interested , read the links above.

    Also , Open the plugin files you have just mentioned and look for the
    Filters and Actions