WordPress content through php

Can someone please give me a hello world example for placing text in a wordpress content page through a custom php plugin?
I have been doing it through creating pages with a div id (through wp-admin) and loading content through extensive amounts AJAX/Javascript into that same id. I want to learn how to do this server side. ( It would make my life soooo much easier )

Related posts

Leave a Reply

2 comments

  1. Are you sure you want to use a plugin? Placing shorcodes in the functions.php file is the easiest route.

    Example

    In your functions.php file

    function caption_shortcode( $atts, $content = null ) {
       extract( shortcode_atts( array(
          'class' => 'caption',
          ), $atts ) );
    
       return '<span class="' . esc_attr($class) . '">' . $content . '</span>';
    }
    add_shortcode('caption', 'caption_shortcode');
    

    In your blog post

    [caption class="headline"]My Text[/caption]

    The above would output. If your output is static, this would be the best way to go.

    <span class="caption">My Text</span>
    

    If you’re sure you want to make it into a plugin, you can do that too. Simply putting this code in a file and putting it into your plugins directory will work. Make sure that you use the proper standards when defining the plugins (see link below).

    The last link has both mentioned in the blog post and has a nice plugin that you can use for your own needs. That blog post explains how you can use the shortcodes in widgets as well.

    Links