Making a plugin operate through a shortcode - wordpress

Many plugin need some [shortcode] to be placed in a page, sometimes within the loop. But usually it only makes the actual [shortcode] appear where I placed it and nothing else !
For example such and such contact form plugin asks me to put [contact form plugin] in my contact page and I'm supposed to see a form appearing there as a result, but instead I see a blank page with the shortcode appearing.
I'm relatively new to WordPress so this question must sound stupid, stil can anybody take the pain to explain to me ?

AFAIK, [shortcode] is intended to be appeared or operated within the loop. if you want it to display outside it (says, on sidebar, or on footer) you need to manually compute it's value.
To do that, you can use do_shortcode() function:
<?php echo do_shortcode ( '[your-shortcode-text]' ); ?>

Related

Find from where the data comes to "the_content()" function

This might look an ordinary question though I'm stuck in it. I'm new to the wordpress. I've bought a wordpress theme and I'm trying to edit some pages as I want. Now I want to edit the default post page where I've already started editing the "single.php" and "post-format.php" files. I want to know from where or how "the_content()" function gets data?
Since I want some html part of the page to be removed though that html part comes through a "the_content" function. Therefore, I'm unable to remove that part without getting rid of "the_content" function. But I can't get rid of "the_content" function because the very same function calls some important part too.
Hope you guys can help!
From Where
As a function get_the_content() retrieve the post content (Generally Used in a Loop) from database and prints on the frontend.
And again the_content() as filter controls how you show the post content.
How
Dead simple answer by WordPress API. You need to understand WordPress Database_API for in-depth understanding.
Frequently Used by
wp-includes/plugin.php: apply_filters()
wp-includes/post-template.php: get_the_content()
wp-includes/post-template.php: the_content
Usage Case: (from Codex)
post_password_required()
get_the_password_form() if post_password_required() fails
wp_kses_no_null() while processing the tag.
balanceTags()
get_permalink()
global: $id, $post ,$more, $page, $pagesm, $multipage, $preview, $pagenow
Ref:
- Filter the_content() | Functionthe_content()
Optional: Offline WP Codex Docs Search/Browser for Windows/OSx

Using Nonce-field in Custom Meta Box plugin, unable to save data

I have been struggling to create a plugin that would allow my customer to update their contact info. I've managed have the plugin show the fields in the admin-area of the frontpage (only want to show the info there). As I fill in the information & press update post, fields go blank and nothing gets saved.
I believe I've isolated the cause to the nonce-field, tested by having some of the fields in an if-statement where I tested for isset & wp_verify_nonce. The fields disappeared, thus the nonce isn't working correctly. What am I doing wrong?
This is my first Wordpress-site that I'm working on so the solution of using multiple fields might not be the most clever but seemed the most simple to wrap my head around.
As a side question, am I right in assuming that I can echo the contents of a field (for example the 'h3_nimi' by using echo get_post_meta( get_the_ID(), 'h3_nimi', true );?
Hopefully it's ok to use pastebin to avoid cluttering the post as the code is rather long due to multiple fields? Thank you in advance.
http://pastebin.com/fqRW2Yyx
Your nonce is created as tt-tallennus but you are checking against tt_henkilosto so the check will always fail.

Adding A Button Between post-content and Related Posts Thumbnail Plugin on WordPress

I am trying to add a button to my WordPress template. Basically, I have the post and then there is the Related Posts Thumbnails widget that appears. I want the button to go between the text of the post and the related posts thumbnail widget. The code in my 'Single Post' that contains all of this is as follows:
<div class="post-content">
<?php the_content(__('<em><strong>More:</strong> Read the rest of this entry...</em>', 'life-is-simple')); ?>
</div>
I know the Related Posts Thumbnails plugin falls within this code because it's at that place when I 'Inspect Element' on Google Chrome. I can't find how to edit the order of things within that div though. Any help would be greatly appreciated, thanks!
EDIT
Clarification: I am using the Life Is Simple WordPress theme although it has been custom editing quite a bit (mostly on the CSS side of things though).
That plugin is probably appending the output to the_content with a filter .
That means , that the output is being added to the_content automatically. it is a common behaviour.
You need to look at the pluginĀ“s admin interface to see if you can have an alternative way (I believe there is ) which is using a template tag. in that case, you should put the template tag after the div where the the_content() is .
EDIT I :
After a small dig, - in fact there is - you need to put
<?php get_related_posts_thumbnails(); ?>
Then the plugin should know by itself not to append to the_content.
For parameter passing, or if something is not working, go read their APi or help files.
You'll probably need to edit single.php or archive.php in your theme. If nothing is occuring there that looks familiar, it's probably using a loop. In which case you might find what you are looking for either in loop.php, loop-single.php, or loop-archive.php depending on what type of page you are on and how the theme was constructed. Add your button near where you find Read the rest of this entry...
With more information (such as what theme you are using), one might be able to help more as well.

Insert a plugin manually into wordpress page

I am working in worpress front page.
I want to add a plugin to the page at a specific location manually but adding the code to the page myself.
I basically want to include a plugin in a certain page on a certain location. So I'm create a div...
<div id="plugin-holder">
**Plugin-will-appear-here-with-this-code**
</div>
Don't anyone know how this is done please?
Thanks
If you're wanting a plugin to appear somewhere, you'll be looking for "shortcode" functionality.
This is actually surprisingly easy to code, check out the examples in the Codex under Shortcode API - ie:
function bartag_func( $atts ) {
// ... do more things here ...
return "text to replace shortcode";
}
add_shortcode( 'bartag', 'bartag_func' );
Once you've called these functions you can use [bartag] in code and it will run your function and replace the shortcode with the generated text your function returns.
If you're adding shortcode functionality to your site, it generally makes most sense to code a really simple plugin and put it in that. The reason why this works best is that, over time, it's really easy to forget and upgrade a theme by mistake (or even change to a new theme) and thus break your site by losing your custom code in your former functions.php. Surprisingly, this is pretty easy to achieve and only requires some specially formatted comments at the top of your plugin file and a little common sense in coding - there are many tutorials and "how to"s around!
Here's a useful shortcode tutorial: http://www.reallyeffective.co.uk/archives/2009/06/22/how-to-code-your-own-wordpress-shortcode-plugin-tutorial-part-1/
You should add the relevant plugin code to functions.php.
I suspect you'll want to use some conditional tags, like is_home() to pinpoint your location. But maybe not, depending on what you are trying to do,
Also, if you're trying to to insert from a pre-existing plug-in, make sure you remove the register_activation_hook or activate_pluginname action.
If your plugin supports a sidebar widget you can simply "widgitize" the div tag that you wish to insert the plugin into.. Google the term and you are gonna find many resources.

WordPress - how to insert html code selectively in posts

I want to display custom html code when a post is rendered (so not when is inserted into the database).
I currently do this with add_filter('the_content', 'my_custom_method'). The only problem is that I want this do be displayed only inside the post (when is viewed in its own page), not when all posts are rendered .
I banged my head against the wall, but couldn't find any method to tell me if i'm currently inside an individual post or not (this has to work for every url rewriting possible, so i can't rely on url)
Is there such a method? I believe it should be, but i can't find it. Thanks.
the function for checking if the post is in its own page is is_single()
add_filter('the_content', 'my_custom_method');
function my_custom_method(){
if(is_single()){
//code for your custom html code
}
}
the function is_single() checks if the page being rendered is a single page or not.
The easiest way to do this would be to modify your templates. Wordpress template sets should have a file named single.php (inside wp-content/themes/<theme name>). This is the page that gets rendered when you are viewing the page for a single post.
You could edit this file and insert whatever you needed to for the posts there.

Resources