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);
Related
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]');
?>
I'm trying to build my own Wordpress Plugin and right now I'm stuck in creating my shortcode (everything else in the backend works just fine). Basically Im trying to set up the code like:
//Function to display the shortcode
function my_shortcode($atts) {
include 'my_shortcode_content.php';
}
As you can see I am trying to just simply include the content from an external php file and not write it directly into the function.
The my_shortcode_content.php looks like this:
<?php
global $wpdb;
$table_name = $wpdb->prefix . "test";
$table_name_categories = $wpdb->prefix . "test_categories";
$stuff = $wpdb->get_results("SELECT * FROM ".$table_name);
$categories = $wpdb->get_results("SELECT * FROM ".$table_name_categories);
echo "<div>Test</div>";
?>
Now the problem is that when I try to echo my HTML Code or even try to put the raw HTML Code outside the -tag I cannot edit my page anymore.
Everytime I try to edit the page in wordpress (where I have my shortcode implemented in a simple text field) and hit save, it only tells me that the update failed and the changes I made in my page are not saved. Now the weird thing is, if I add stuff to my shortcode content file it will display the change on the page, but if I want to remove / edit something else that is not my shortcode, I simply can't because it throws me an error. BUT if I remove the HTML Code from my shortcode content page, everything works just fine and I can edit my page again.
Does anyone know how what could cause this problem?
Btw I'm using docker-wordpress to test my stuff, tho I do not think that this could cause the error.
(Total newbie here and not a web developer by any means. Thought I'd try and ask since my Google queries typically bring me to this site anyway.)
I am using a WordPress theme, Corporate Plus. The button on the homepage will not take whatever link I input through the Customizer.
Preview of what I'm seeing (the "Let's Get Started" button): http://ruleyourcompetition.com/?customize_changeset_uuid=105d9013-cf7a-4d54-9808-0039f71eb423
Per another thread I found here on StackOverflow, it seems like I can edit the function.php file with:
function custom_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '">' . __("Your Read More Link Text", "your_theme_slug") . '</a>';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
However, I'm not sure what changes to the above code I might need to make, if this is the recommended way to go about it. I tried the simpler fix mentioned in the replies on that other thread, but that didn't seem to do the trick.
Trying not to break the site. Can anyone recommend advice?
Thank you!
I'm currently coding for a wordpress theme and are creating specific pages, one function that i wanted to do is that if there's an existing cookie, it echoes a menu while without an existing cookie, it echoes something else.
One problem that I encounter is with the echo function, the bloginfo('template_directory') doesn't work in my script.
Here's an overview
echo 'LOGOUT
<div class="para">Temporary giving up super power.</div>';
I tried blackslashing it and it only gave me a more confusing link with the whole bloginfo('template_directory') in it. e.g. www.yoursite.com/bloginfo('template_directory')/logout.php.
Use get_bloginfo() to put the info in a variable.
$templateDirectory= get_bloginfo('template_directory');
echo 'LOGOUT<div class="para">Temporary giving up super power.</div>';
You should consider using the function get_stylesheet_directory_uri(), as suggested in Codex entry for get_bloginfo.
get_sytlesheet_directory_uri searches first in the child theme directory, and if the file does not exist, or it is not a child theme, then the main theme directory is looked into:
echo '<a href="'
. get_stylesheet_directory_uri()
. '/logout.php" class="linkit">LOGOUT</a>'
. '<div class="para">Temporary giving up super power.</div>';
Anyone familiar with WordPress shortcodes? I could really use a hand! I've inserted the following code into my functions.php file for the theme I'm using...
function create_slideshow_header($atts, $content = null){
return '<div class="item_heading">'.$content.'</div>';
}
add_shortcode('slideshow_heading', 'create_slideshow_header');
function create_slideshow_white_header($atts, $content = null){
return '<span id="dyn">'.$content.'</span>';
}
add_shortcode('slideshow_heading_white', 'create_slideshow_white_header');
function create_slideshow_content($atts, $content = null){
return '<div class="item_content">'.$content.'</div>';
}
add_shortcode('slideshow_content', 'create_slideshow_content');
Now, I was led to believe by several tutorials that this should allow me to insert the following into the text editor in the WP backend...
[slideshow_heading]SLIDESHOW HEADER[/slideshow_heading]
...and the SLIDESHOW HEADER text would be wrapped in the appropriate HTML.... but it's just displaying the above as regular text. I've cleared my cache, etc...
Is there something I'm doing wrong? Thanks in advance!
SOLUTION
I failed to mention that I was using the page.ly MultiEdit plugin--which uses "custom fields" to create extra editable regions. WordPress conveniently doesn't parse shortcodes in custom fields. Normally, you can create a filter for each custom field, but since this is a plugin, you can just edit the multiedit.php file, and change line 63 from
echo $GLOBALS['multiEditDisplay'][$index][0];
to
echo apply_filters('the_content',$GLOBALS['multiEditDisplay'][$index][0]);
With a little work, you can turn Wordpress into a truly amazing CMS!
I actually checked out your code, it works for me. Your usage is right.
Try adding a die() in there to see whether the method is called in your case.