Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Hot answers tagged

11

Don't know if i agree with EarnestoDev answer which is more of an opinion then an answer based on facts and not true in all cases, since you can use jQuery to trigger the submit event when a different element is clicked, so just add this js code once <script> jQuery('.metabox_submit').click(function(e) { e.preventDefault(); jQuery('#publish')....


10

So I'm answering my own question, for those that face or will face the same problem. I have added two buttons. One opens wordpress' build-in window to select a post and inserts the link. The other opens wordpress' build-in media window to select an image. That is what somehow what you get at the end. You will need two PHP functions and one JS one in a ...


9

You can use wp_delete_post. To get all posts with the "trash" status: $trash = get_posts('post_status=trash&numberposts=-1'); Then: foreach($trash as $post) wp_delete_post($post->ID, $bypass_trash = true);


7

I had the exact same problem and found the solution to this. The problem is that the anchor plugin for TinyMCE is not being included as part of the default Wordpress install. So while Wordpress says to include: $buttons[] = 'anchor'; …that's not going to work because the TinyMCE plugin for anchors isn't there. If you go to TinyMCE's website, you can ...


6

With WordPress 3.5+ Media Uploader, there's another way. All strings are localized at the bottom of the page with: <script type='text/javascript'> /* <![CDATA[ */ var _wpMediaViewsL10n = { "url":"URL", "addMedia":"Add Media", "search":"Search", "select":"Select", "cancel":"Cancel", "selected":"%d selected", "dragInfo":"...


5

Filter 'gettext', take care to catch the target string only by checking the text domain. See this answer for a rather verbose example. A simplified way: add_filter( 'gettext', 'wpse_41767_change_image_button', 10, 3 ); function wpse_41767_change_image_button( $translation, $text, $domain ) { if ( 'default' == $domain and 'Insert into Post' == $text ) ...


5

Like this: function custom_js_to_head() { ?> <script> jQuery(function(){ jQuery("body.post-type-YOUR-CUSTOM-POST-TYPE .wrap h1").append('<a href="index.php?param=your-action" class="page-title-action">Import from ...</a>'); }); </script> <?php } add_action('admin_head', 'custom_js_to_head'); ...


4

Unfortunately this isn't possible (without a slight hack)- since there are no hooks provided (see for example the edit.php page). A quick and easy hack is to use JavaScript to add the link after the usual 'Add New' link. Here I've used the admin_print_footer_scripts hook (on 'post', or 'edit-post' screens) to print the JavaScript. Note that you must alter ...


4

It's very likely that your test is broken because of conflicts. You are essentially loading two versions of all your UI scripts. That is because the Google CDN version of JQuery UI is not the core, but the entire script library (including datepicker, autocomplete, etc), as opposed to the WordPress scripts, which are broken into pieces which tend to be ...


4

DON'T DO IT! There's reasons why FORMs have centralized submits. Because there's some processing done behind the screen and one button is safe. Having an extra button in all your Metaboxes will also take up more space. The easier you make it for the user to press the button, the safer it is to bet he'll forget something. The more difficult it is to submit a ...


4

t31os answer is great. Just a side note: to obtain the path to the image add init : function(ed, url) { theurl = url; }, right before createControl: function... and now you can use it in var c = cm.createSplitButton('onehalf', { title : 'My split button', image : theurl + '/theicon.png', onclick : function() { tinyMCE....


4

You can add button via add_meta_box function. function add_your_meta_box(){ add_meta_box('your-metabox-id', 'Title', 'function_of_metabox', 'custom_post_type', 'side', 'high');} add_action('add_meta_boxes', 'add_your_meta_box'); function function_of_metabox() {?> <input type="submit" class="button button-primary button-large" value="Add New" ...


4

The code below should be something similar to what you're looking for Inside the loop template you use for listing blogs (like index.php) you need something like this <a href="<?php the_permalink(); ?>/#respond"> <!-- The blog permalink with the anchor ID after --> <i class="fa fa-comments-o"></i> Leave a Comment </a>...


3

Solution based in this StackOverflow Q&A. Well, more a proof of concept than anything... Style and scripts being printed the lazy way. Add a fixed Scroll to top div linked to an anchor near the Publish button. add_action( 'admin_head-post.php', 'scroll_to_top' ); function scroll_to_top() { ?> <style>#box { /* Position ...


3

Here is something i have used before as a solution for changing the post category (or any term/taxonomy) just make sure you set the right $post_type,$append,$taxonomy,$terms <?php /* Plugin Name: Simple Ajax set cat Plugin URI: http://en.bainternet.info Description: dead simple lightweight plugin to add a post row action link to set a post category by ...


3

For something like this you might consider adding an 'action'; which appear when you hover other the item. The following code is not complete, and hasn't been tested - but should get you on the right track. Add the action First, to add the action link, use the tag_row_actions hook. (Keep in mind a function hooked onto this will be fired on every taxonomy, ...


3

add_filter("attribute_escape", "myfunction", 10, 2); function myfunction($safe_text, $text) { return str_replace("Insert into Post", "Use this image", $text); } Place in your theme functions file of in a plugin file. The first usable filter that this button hits is on the function esc_attr(). So what that code will do is find any instance of Insert ...


3

It looks like you're trying to use classes from the WordPress admin styles on the front end. However, those styles are not loaded. You have two options, one of which I wouldn't recommend. Way #1: Do this What I would recommend is that you simply copy and paste the buttons styles you want into your child theme or custom CSS plugin (example, one of many). ...


3

There is an action before the Trash link: post_submitbox_start. You can use it to add content to that box. The Trash has a float:left, so it will move to the side. Example: add_action( 'post_submitbox_start', function() { print '<button>Hey!</button>'; }); Result:


3

Your div wrapper is within your while loop, and split by your if clause. This cannot work properly, since your loop will generate up to 14 divs with the id ajax. Put the opening div tag after if ( $the_query->have_posts() ) { and the closing after wp_reset_postdata(); and you should be fine. Edit Are you sure, that you didn't miss any opening/closing ...


3

Use media_buttons action for it. Check below code. add_action('media_buttons', 'add_my_media_button'); function add_my_media_button(){ echo '<a href="'.get_site_url().'/wp-admin/customize.php" class="button button-default">Customize</a>'; } Hope this will helps you. Thanks!


2

You can stimulate click to Update post button like this.. Adding submit or update button to custom metabox? <script> jQuery('.metabox_submit').click(function(e) { e.preventDefault(); jQuery('#publish').click(); }); </script> <input type="submit" class="metabox_submit" value="Submit" />


2

You can style a link as a button with the button css class: <a href="#" class="button">I am a button</a> You can modify a button with the primary styling by adding button-primary: <a href="#" class="button button-primary">I am the primary button</a>


2

Okay, I did it this way:: add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2); function special_nav_class($classes, $item){ if(is_category() && $item->title == "Blog"){ //Notice you can change the conditional from is_single() and $item->title $classes[] = "special-class"; } return $classes; }


2

WARNING: using the hook "attribute_escape" is kinda bad. This function is called for ALL text including post titles and content. Using this filter as stated in the accepted answer breaks html entity encoding. For instance the title Features & Pricing appears as Features & Pricing in the title field. After saving it then shows Features &amp; ...


2

I'll only outline how to do it since there are plenty of answers on this site that address how AJAX works in WordPress. Just check out the ajax tag. Yes, you'll need some javascript to watch for when the button is clicked. When it is, you send a custom action, say 'myaction', and the post ID (and possibly a nonce) to the WordPress' admin-ajax page. You ...


2

it you're not seeing the buttons, try to call QTags._buttonsInit(); right after you call the quicktags( settings ); function. quicktags(settings); QTags._buttonsInit(); Following also works for me qt_editor = new QTags( { 'id': 'my_editor', 'buttons': 'strong,em,link' } ); QTags._buttonsInit(); Also, it seems that adding a button via QTags.addButton() ...


2

This is the intended behaviour on an iPhone or other mobile device (it's called 'responsive design'). Because you have a much narrower screen on a mobile it's very likely that if you have more than four or five top-level pages, the navigation menu starts to wrap on to two lines and become messy & difficult to use. There's no simple disable option, ...


2

Your method is complex... Here is simplest function to add BUTTON in TinyMCE: (insert this code in funcitons.php): add_action('admin_init', function() { if (current_user_can('edit_posts') && get_user_option('rich_editing') == 'true') { add_filter('mce_buttons_2', 'register_buttonfirst'); add_filter('mce_external_plugins', '...


2

It's simple, use the function is_user_logged_in: <?php if ( is_user_logged_in() ) { ?> <a hef="link-for-logged-users"></a> <?php } else { ?> <a hef="link-for-users-not-logged-in"></a> <?php } ?> See here http://codex.wordpress.org/Function_Reference/is_user_logged_in


Only top voted, non community-wiki answers of a minimum length are eligible