anon5456919
anon5456919

Reputation: 383

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 )

Upvotes: 1

Views: 120

Answers (2)

JohnP
JohnP

Reputation: 50039

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

Upvotes: 1

DXL
DXL

Reputation: 149

Use the Exec-PHP plug-in: http://wordpress.org/extend/plugins/exec-php/

Upvotes: 2

Related Questions