-
▼
2012
(336)
-
▼
September
(25)
- How to Use External Domain Names With WordPress
- How to Make a DIV Link in WordPress
- How to Embed Links Within a Picture in WordPress
- How to Install Thematic WordPress Themes
- How to Install WordPress on a Pair.com Account
- How to Add Your Blogspot Friends on WordPress
- How to Change Your WordPress Template
- How to Upload a WordPress Blog on to My HostGator ...
- How to Embed a Podcast in WordPress
- How to Transfer WordPress to New Domain Using File...
- How to Change the Color on a WordPress Template
- How to Upload Videos to Wordpress
- How to Upload HTML Files to WordPress
- How to Set Up WordPress AWS C2
- How to Connect FeedBurner to WordPress
- How to Publish Scheduled WordPress Posts
- How to Make a WordPress Ping
- How to Install File Share in WordPress on CentOS
- How to Post Web Clips to a Wordpress Blog Directly...
- How to Email a Blog Entry to WordPress
- How to Put Your WordPress Page in FileZilla
- How to Add a Short Code to WordPress
- How to Activate WordPress in GoDaddy
- How to Create a Home Page with WordPress
- How to Rename a WordPress Theme in the Dashboard
-
▼
September
(25)
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]
7:46 AM | Filed Under | 0 Comments
Post a Comment