Trying To Create Some Shortcodes

Greetings, I am stumped and I hope someone can help.

I am trying to take the input from a theme option and create shortcodes with them so that I can use the information throughout my site.

In the header.php of this theme I see them using the following at the very top of the file;

<?php global $cbt_options; ?>

then in the body of the file, they pull name, email, and phone which is stored in the theme options like this;

<?php echo $cbt_options?>

I am trying to turn this into a short code, so I created a plugin as such;

<?php

global $cbt_options;

/*

Plugin Name: Customize Market Center

Plugin URI: http://intimatetickles.biz/it_mc_shortcodes

Description: Add Shortcodes Using Theme Options – Upload and Activate.

Author: Storme Brown

Version: 1.0

Author URI: http://webstorme.com

*/

// Add Shortcode Consultants Phone

add_shortcode( ‘consultant_phone’ , ‘fn_get_consultant_phone’ );

function fn_get_consultant_phone(){

$cbtconsultantphone = ($cbt_options);

return $cbtconsultantphone;

}

?>

But this did not work. SOMETHING seems to be happening, because the shortcode itself disappears from the page, but it is not replaced with the content.

Any chance you might be able to help me out with writing this code? Or perhaps – is this an impossible task?

I can see the information in the database in wp_options and wp_4_options (multisite). Is this the problem?

Thanks

Derek Brown.

  • Sajid
    • DEV MAN’s Sidekick

    Hi Derek,

    Hope you are doing good today :slight_smile:

    You are doing it almost right and on right direction. You just need to add global options variable inside functions of your shortcode callback.

    Change your function from:

    function fn_get_consultant_phone(){
    $cbtconsultantphone = ($cbt_options['social-phone']);
    return $cbtconsultantphone;
    }

    To:

    function fn_get_consultant_phone(){
    global $cbt_options;
    $cbtconsultantphone = ($cbt_options['social-phone']);
    return $cbtconsultantphone;
    }

    Note the global variable on first line of above function.

    Hope it helps :slight_smile:

    Cheers, Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.