Enable shortcodes in a wordpress theme - wordpress

I develop a new theme for wordpress 3.3.1 from scratch and shortcodes are not working on it.
As I searched until now it is a matter of filtering the content containing the shortcode, filter code added in a theme specific location(shorcodes are working with another theme).
So, my question is : What is the code for a general shortcode theme enable ?

To execute a single shortcode, run it with
echo do_shortcode('[your_short_code]');
If the shortcode(s) are in the post content, make sure you're displaying it with
<?php the_content();?>
Or
<?php echo apply_filters('the_content',$post_content);?>
Or
<?php echo apply_filters('the_content',$wp_query->post->post_content);?>
The important thing is: if you aren't using the function "the_content()" you need this line <?php echo apply_filters('the_content',$wp_query->post->post_content);?> where in the second argument you have to put the variable of the post content you want to show.

I had to save the theme's content to a variable and then use the second example.. Worked like a charm.
$mycontent = ot_get_option('rightcontent');
echo apply_filters('the_content',$mycontent);

Related

How can I call a WordPress shortcode in specific template

I use Simple Blog Stats WordPress plugin and I want to show numbers of users. Simple Blog Stats WordPress plugin has a shortcode [sbs_users]. But I want to show it on specific template - search_paralex_2.php and I can't use shortcode here. I try
<?php echo do_shortcode('[user_count]'); ?>
But I get result - [user_count]
Did you try this ?
<?php echo do_shortcode('[sbs_users]'); ?>
The shortcode you write in your example is [user_count]

How to add extra Widgets in wordpress?

In my current WordPress theme, i have some 5 widgets.
I tried with plugins available on internet but that not solved my problem.
I want to use more widgets in my theme in single sidebar.
How can i add more widgets in WP theme?
Thanks
Most widgets give you a shortcode to put into one of the pages that wil be echoed out through the the_content(); function.
So if you would like to process those shortcodes in the PHP to make them in custom places would probably be your best bet.
You can do that like this:
<?php echo do_shortcode( $content ) ?>
Here is the reference

How to use wordpress shortcode in template

I need help with wordpress shortcode. I have written shortcode function in functions.php in my theme files. Now I create page in wordpress administration and then I need to place this shortcode into special place in my theme but with content which I wrote in administration.
I hope that you understand what I mean.
Thank you for your help.
In your template code:
<?php echo do_shortcode('[your-shortcode]'); ?>
Replace [your-shortcode] with whatever your shortcode is, including parameters/attributes and/or closing tags if required.

Show all post content on Wordpress

Im using the theme HTML 5 Blank (http://html5blank.com/) with WordPress 3.7.1.
On my page I want to display everthing from the posts, text and images.
In the settings in wordpress admin i have it set on show hole post but it does not work.
I have olso deleted the php code in the loop that inserts the excerpt from the theme. Sitt not workning. Any ideas? I can send code if you want, for now i do not know what code can be usefull.
Jim
Replace <?php the_excerpt() ?>and add the following code to your theme's loop.
<?php the_content(); ?>
That should display the content, rather that the excerpt.

adding single.php page to wordpress or if condition for main page or post detail page

I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul

Resources