Jump to content
xisto Community
Sign in to follow this  
Ahsaniqbalkmc

Wordpress Shortcode Api: Using Variable Inside Shortcode

Recommended Posts

I have been digging deep into wordpress plugin development (at least trying to) so that I can develop some plugins for my website that would enhance its user experience and reduce the maintenance efforts. One of the planned plugins is one that handles some shortcodes for me.
Wordpress has provided a rich API for shortcode development and it is quite fun to use. But I am stuck with one issue that I need to resolve. The plan is to create a shortcode which uses a variable as the word. For instance the following code will register a shortcode [home] that will be converted to a link to the home page.

add_shortcode('home', 'show_home_link');function show_home_link () {return '<a href="http://http://www.mysite.com/;;}

But what i need is that the word "home" be a variable $var. The plan is to check the value of $var agains the post_title entries of the wp_posts table of the wordpress database. And then according to the match found, display appropriate link to that specific page. This would make me able to just say [about] to post a link to about page. or [my first blog post] to post a link to the post with title "my first blog post".

I know how to develop the function to check agains database entries and produce corresponding link but what I don't know is how to make the shortcode use a variable entry.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.