• Hello.

    This should be very simple but for me, I am learning wordpress for the first time although I am good in PHP.

    I would have a php code which I wish to have as a plugin. However, when I paste the shortcode in a post, the shortcode does not work.

    Here is a simple plugin I am working with as a dummy.

    <?php
    defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
    /*
    Plugin Name: My Leap Year
    */
    function test() {
    echo'Is the shortcode working?';
    }
    add_shortcode( 'leap', 'test' );

    The shortcode [leap] does not work when I paste it in a post/page. How can I make it work?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try this:

    function example_shortcode() {
       return 'Is this shortcode working?'; // return the content
    }
    add_shortcode( 'examplesc', 'example_shortcode' );

    Simple difference is returning the string. Just place in [examplesc] in any post/page.

    I use a ton of custom shortcodes and I updated to 4.5. It’s working just fine.

    there is information about creating shortcodes in the Codex https://codex.www.ads-software.com/Shortcode_API

    Thread Starter leapyear16

    (@leapyear16)

    Thread Starter leapyear16

    (@leapyear16)

    I finally got it working by using this code;

    <?php
    defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
    /*
    Plugin Name: 1245378
    Description: This plugin was created to do bla bla bla...
    Version: 1.0
    */
    function test_me() {
    require_once('mr_happy.php'); //This is a script that executes some other tasks.
    }
    add_shortcode( 'leap', 'test_me' );

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Plugin Shortcode in wordpress 4.5 not Working’ is closed to new replies.