I need to to add a short code into a short code in WordPress.
[mycred_link href="http://www.mycred.me"]View portfolio[/mycred_link]
This short code above is a short code from myCred plugin, it gives users points when they click on the link inside the short code.
What I need is:
To show a Facebook share link, inside the short code using. I already have a short code that generates a Facebook share link.
I need something like this:
[mycred_link href="[facebook_share_link]"]View portfolio[/mycred_link]
To give users points when they share my posts on Facebook. I tried it but it didn't work.
I also tried this code below, it Gives point to users and opens facebook.
But facebook says that URL is invalid.
<?php echo do_shortcode( "[mycred_link href='http://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode(get_permalink()); ?>']View portfolio[/mycred_link]"); ?>
If I put double quote after the href the wordpress footer will disappear completely, am running the second code on my footer.php
The problem is inside the code of myCred plugin. As you can see from the source code of the plugin wp-content/plugins/mycred/includes/shortcodes/mycred_link.php what you pass inside the href attribute doesn't get parsed with do_shortcode therefore you will not be able to insert.
As you can see from this answer:Shortcodes inside a shortcode - wordpress wordpress shortcodes doesn't stack automatically.
Luckily for you the function end with:
return apply_filters( 'mycred_link', '<a ' . implode( ' ', $attr ) . '>' . do_shortcode( $link_title ) . '</a>', $atts, $link_title );
So w/o touching the plugin source code you can use the filter and then do something with the href. My guess is something like this (not tested)
Inside your function.php in your theme folder insert something like this:
add_filter('mycred_link','edit_mycred_link',10,3 );
function edit_mycred_link($link_html, $atts, $link_title){
return str_replace('__edit_mycred_link__',do_shortcode('[facebook_share_link]'),$link_html);
}
And then inside your template file / post content
[mycred_link href="__edit_mycred_link__"]View portfolio[/mycred_link]
That should work
I finally solved the problem. I asked the question on wordpress forum and a moderator gave it to me.
<?php
echo do_shortcode( '[mycred_link href="http://www.facebook.com/sharer/sharer.php?u=' . urlencode( get_permalink()) . '"]View portfolio[/mycred_link]');
?>
Related
this has been discussed before however it's not working for me. As the shortcode seems to be a mix of regular and open-close shortcode. Or a combination of nested shortcodes.
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '' );
// In case there is opening and closing shortcode.
echo do_shortcode( '[iscorrect]' . $text_to_be_wrapped_in_shortcode . '[/iscorrect]' );
This is the shortcode I would like to display in my php template
[mk_page_section bg_stretch="true" full_width="true" padding_top="0" padding_bottom="0" sidebar="sidebar-1"][vc_column][mk_header hover_styles="5" logo="false"][/vc_column][/mk_page_section]
What I am trying to achieve is display my main navigation on a webinar page that doesn't use my themes header or footer.
Is mit possible to use it like this?
<?php echo do_shortcode('[mk_page_section bg_stretch="true" full_width="true" padding_top="0" padding_bottom="0" sidebar="sidebar-1"][vc_column][mk_header hover_styles="5" logo="false"][/vc_column][/mk_page_section]'); ?>
Or must it be a combination? totally lost here...
Why is the do_shortcode not working?
UPDATED: Changed inner div content
Please, understand than I'm new to wordpress and php.
I added a media button to my media buttons in the admin by adding the following code to functions.php file:
function add_custom_media_button() {
echo 'Add custom media';
}
add_action('media_buttons', 'add_custom_media_button', 15);
add_action( 'admin_footer', 'add_inline_popup_content' );
function add_inline_popup_content() {
$cu = wp_get_current_user();
$cusername = $cu->user_login;
echo '<div id="custommedia_container" style="display:none;">';
echo '<iframe class="mediaselectoriframe" title="Archivado" width="100%" height="99%" title="cosas" src="http://nephila.cloudapp.net/GAdEWeb/wpsearch.aspx?wpuser=' . $cusername . '&wplang=' . $clocale . '" frameborder="0"></iframe>';
echo '</div>';
}
Now, this is working on Create Post page, but is not anywhere else.
I can see my button in Edit post, Create page and Edit page, but there's nothing inside the thickbox.
UPDATE: Still haven't been able to fix this problem. I've tried changing everything and nothing has improved. I'd really appreciate if someone could give me a hint, I don't seem to find any info about this, but I can't believe I'm the only one that has ever had this problem
As far as your code not working, you have and error in your echo statement:
echo 'I'm ' . $cusername . ' and I'm testing my media thickbox';
You're single quotes are not properly escaped, so you're most likely generating an error message, which is why your thickbox is blank (WSOD). It should look like this:
echo 'I\'m ' . $cusername . ' and I\'m testing my media thickbox';
Or like this:
echo "I'm $cusername and I'm testing my media thickbox";
As far as how WordPress works... any code you add to manipulate the way the admin interface, or the front end interface, works should be added to your theme's functions.php file, or to a plugin. Changing WordPress core files is a very bad habit to get into because as soon as there is a new update, all of your changes will be overwritten.
In your case, you are adding this code to admin.php, which is inside the wp-admin folder, which is considered a core WordPress folder and file. You basically never want to touch anything inside wp-admin or wp-includes (or even on the root, except for the wp-config.php and possibly .htaccess if you know what you're doing). The wp-content folder is the only folder that will never get touched in a WordPress upgrade. This is why you want to add your code here, and not through the core files.
Move your code above to your theme's functions.php file, and it will still work the same. Make corrections to your echo statement as I have recommended, and you should see the content in the thickbox appear. Let me know if you have any other questions on how WordPress should work, and I'll be happy to help answer them!
I ended up solving this by changing my two functions to only one, and setting the "button" to show the iframe directly, like this:
function add_custom_media_button() {
$cu = wp_get_current_user();
$cusername = $cu->user_login;
$clocale = get_locale();
echo 'Add custom media';
}
add_action('media_buttons', 'add_custom_media_button', 15);
I'm using the wordpress php widget but I am unable to process Wordpress shortcode - the php just renders the shortcode instead of processing it. HEre is what I did
Added filters to my active theme function.php file
add_filter('widget_text', 'shortcode_unautop');
add_filter('widget_text', 'do_shortcode');
// Allow shortcodes in php code widget
add_filter('widget_execphp', 'shortcode_unautop');
add_filter('widget_execphp', 'do_shortcode');
Added the following to the php widget
<?php
$id = get_the_ID();
$amazon_product_asin_value = get_post_meta($id, 'amazon_product_asin', true);
echo do_shortcode('<div> [amazon asin=' . $amazon_product_asin_value . '&template=buynowamazon_widget&chan=default] </div>');
?>
I also tried without do_shortcode and same result.
2 properly outputs the shortcode of
[amazon asin=B008I20FT8&template=buynowamazon_widget&chan=default]
which works fine if I just enter this in the standard text widget
I'm using the Amazon Link plugin which generates the shortcodes
Any ideas?
The asin parameter value might be confusing the shortcode processor; try putting quotes around it.
echo do_shortcode('<div> [amazon asin="' . $amazon_product_asin_value . '&template=buynowamazon_widget&chan=default"] </div>');
Alternatively, does the shortcode accept each argument to that parameter as a separate parameter?
echo do_shortcode('<div> [amazon asin="' . $amazon_product_asin_value . '" template="buynowamazon_widget" chan="default"] </div>');
Edit: Looking at the plugin's code, I don't think you need these lines:
add_filter('widget_execphp', 'shortcode_unautop');
add_filter('widget_execphp', 'do_shortcode');
They will try to process the shortcode, before the PHP is executed, and thus you won't get the shortcode correctly processed. Comment them out and see what the plugin does now.
Can someone please give me a hello world example for placing text in a wordpress content page through a custom php plugin?
I have been doing it through creating pages with a div id (through wp-admin) and loading content through extensive amounts AJAX/Javascript into that same id. I want to learn how to do this server side. ( It would make my life soooo much easier )
Use the Exec-PHP plug-in: http://wordpress.org/extend/plugins/exec-php/
Are you sure you want to use a plugin? Placing shorcodes in the functions.php file is the easiest route.
Example
In your functions.php file
function caption_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'class' => 'caption',
), $atts ) );
return '<span class="' . esc_attr($class) . '">' . $content . '</span>';
}
add_shortcode('caption', 'caption_shortcode');
In your blog post
[caption class="headline"]My Text[/caption]
The above would output. If your output is static, this would be the best way to go.
<span class="caption">My Text</span>
If you're sure you want to make it into a plugin, you can do that too. Simply putting this code in a file and putting it into your plugins directory will work. Make sure that you use the proper standards when defining the plugins (see link below).
The last link has both mentioned in the blog post and has a nice plugin that you can use for your own needs. That blog post explains how you can use the shortcodes in widgets as well.
Links
http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/
http://codex.wordpress.org/Shortcode_API
http://codex.wordpress.org/Writing_a_Plugin
http://aaron.jorb.in/blog/2010/02/wordpress-shortcodes-a-how-to-by-example/
I use stackoverflow very often and just found out in google about this one, Nice :D
Well,
i want to save my every post i write from wordpress to my 3rd (OEXChangeble) website aswell at the same time, so i need to send the info to my website, developing a plugin iguess
I need basically the permalink (and i would be able to extract the rest of the params from my wesite), but better if i can get title, tags, permalink and description(or some of it)
i understand by my google research that all i need to do is add something like
<?php
//header of plugin
function myFunctionThatSendsMyWebsite($url){
// procedure containing a file_get_contents('myqwebsite?url=') request to my website
}
add_action('page_post', 'myFunctionThatSendsMyWebsite', $permalink));
?>
I have problems thoug finding the name of variables i have missing (marked by ???). I know that $post contains all objet, how to extract the info from it (if there is), or if it's complicated, it would be enought for me with permalink
Any tip?
Thanks!
according to this link, this should work, the post id will be sent to this function automatically and you can get anything you want from a post id.
function myFunctionToSendPost($post_ID) {
$post = get_post($post_ID);
$title = $post->post_title;
$content = $post->post_content;
$permalink = get_permalink($post_ID);
...
sendToYourServer($params);
return $post_ID;
}
add_action('publish_post', 'myFunctionToSendPost');
BTW, this function is called when a post is published, you can change it to happen when saved by
add_action('save_post', 'myFunctionToSendPost');
add these lines to your theme's functions.php file.
1) While this doesn't take advantage of the save_post feature, you can even use this code to display blog posts on a completely separate web site, as long as it’s on the same server and you have filesystem access to the WordPress directory on the original site. Simply modify the require() in the first block on this page to use the full path to your WordPress installation:
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('/var/www/example.com/wordpress/wp-load.php');
query_posts('showposts=1');
?>
position your post with a while loop:
<?php while (have_posts()): the_post(); ?>
<?php endwhile; ?>
if you want to specify which parts of the post to display use this code:
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p>Read more...</p>
<?php endwhile; ?>
2) How about using the rss feeds from your wordpress blog?
The following code will display a list of your feed titles with descriptions including a hyperlink to the original WordPress posts:
<?php // Load the XML file into a Simple XML object
$filename = http://feeds.feedburner.com/<em>yourfeedname</em>";
$feed = simplexml_load_file($filename);
// Iterate through the list and create the unordered list
echo "<ul>";
foreach ($feed->channel->item as $item) {
echo "<li><a href='" . $item->link . "'>" . $item->title . "</a></li>";
}
echo "</ul>";
echo "<li>" . $item->description . "</li>";
?>
3) Feedburner has a free feature called BuzzBoost where you can get your posts to show in a regular HTML website that once activated you can simply copy the script that they provide into your HTML where you want the list to appear. From your feedburner account you can adjust some elements like whether the Blog title should appear or not, the format of the date, etc...
You can also style the output using regular CSS within you websites existing CSS.
Check it out Feedburner here:
https://www.google.com/accounts/ServiceLogin?service=feedburner&continue=http%3A%2F%2Ffeedburner.google.com%2Ffb%2Fa%2Fmyfeeds&gsessionid=5q8jqacBluH1-AnXp08ZFw
Are you trying to save a copy of the post somewhere else when they first publish the post? Or on every page view?
You can trigger it when the post is saved by writing a plugin that implements the save_post hook:
http://codex.wordpress.org/Plugin_API/Action_Reference
To do it on every page, you'd probably write a plugin with a filter hook on the page (if it's something you want other people to use) or if it's just one site, you could add it to your theme.
But... Are you sure you want to do this? It seems like your keepyourlinks site might be better implemented as an update service: http://codex.wordpress.org/Update_Services