adsense

How to Add a Short Code to WordPress





1. Open your 'functions.php' file in a code editor and scroll down to the bottom. Write a function that returns whatever output you want to appear whenever you use the finished short code. Here is an example:function some_stuff() {return 'Whatever you want to output.';}
2. Add this built-in WordPress 'hook' function below the short code function:add_shortcode('myshortcode', 'some_stuff');Replace 'myshortcode' with whatever you want to name your short code. This is the name you will use when typing the short code in a post. Replace 'some_stuff' with the name of the function that handles the short code's output.

3. Change your code like this if you want to add an attribute to your short code:function some_stuff() {Extract(shortcode_atts(array('thing' => ''), $atts));Return '
'.$content.'
';}Replace 'thing' with the name you want to give your attribute, such as 'href' for a short code that creates links or 'columns' for a short code that creates columns. Return a string containing the tag code and concatenate -- break the string to add in more PHP code -- the attribute as a variable into the string. Also concatenate the variable 'content' between the tags.
4. Upload your edited 'functions.php' file and save it over the earlier version. Log into the WordPress dashboard and edit a post. Click the 'Visual' editor tab and then write out your short code in the post like this:[myshortcode thing='some-value']Content goes in here.[/myshortcode]

Comments

0 Responses to "How to Add a Short Code to WordPress"

Post a Comment

Popular Posts

About