New answers tagged

2

Just put two and two together: <img src="<?php $bigimg = get_post_meta( $post->ID, 'bg_file', true ); echo wp_get_attachment_url( $bigimg ); ?>" srcset="<?php echo wp_get_attachment_image_srcset( $bgimg, 'medium' ) ?>" alt="" />


0

You create two date objects and compare with the diff() methode. $from = new DateTime( '1970-01-01' ); $to = new DateTime('today'); $years = $from->diff($to)->y; $months = $from->diff($to)->m; echo $years . ' years and ' . $months . ' months.'; => 46 years and 1 months.


1

You can remove dashboard widgets/metaboxes using the following action, wp_dashboard_setup: Example 1 function remove_dashboard_widgets() { global $wp_meta_boxes; $wp_meta_boxes['dashboard']['normal']['core'] = array(); $wp_meta_boxes['dashboard']['side']['core'] = array(); } add_action('wp_dashboard_setup', 'remove_dashboard_widgets', ...


0

Had similar problem ($post was null inside the rendering function). Sorted with the solution below: function bg_post_categories_shortcode( $atts, $content = null ) { global $post; $categories = get_the_category_list( ', ', '', $post->ID); return '<div class="gi__categories">' . $categories . '</div>'; } ...


0

The default themes, TwentyXXXX, do it somewhat like this: add_action( 'wp_enqueue_scripts', 'wpse217390_enqueue_google_fonts' ); function wpse217390_enqueue_google_fonts() { $query_args = array( 'family' => 'Dosis:400,600,700|Roboto:400,400italic,700,700italic' ); wp_register_style( 'google-fonts', add_query_arg( $query_args, ...


0

This little plugin shows the user role 'author' only its own categories & posts. So you can edit it for your own post-type and taxonomy. /* Plugin Name: Show own categories Description: This plugin shows the user role 'author' only its own categories & posts Version: 0.1 Author: Soren Wrede License: GPL2 License URI: ...


0

I believe the issue here is a problem with vernacular. is_active_sidebar isn't page specific -- just checks to see if it has data within it throughout the entire site. You are asking a different question. Sounds like you are asking "does this template reference and sidebars AND do any of those sidebars have data in them,?" it also sounds like you don't ...


0

You can either place entire code into an array as below: $safe= array( 'get_template_part(\'content/block\', \'branding\');', 'get_template_part(\'content/block\', \'footer\');' ); And then introduce the below check into your function to make sure that no kind of code other than what you already listed can be sent to eval: function ...


1

This question has been answered on Stack Overflow before: http://stackoverflow.com/a/14626254/844732 add_action( 'admin_head', 'check_page_template' ); function check_page_template() { global $post; if ( 'page-homepage.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) { // The current page has the foobar template assigned ...


0

Something you may use to accomplish this a plugin with a role and capability manager. You could then assign whatever permissions to either role you want, or create a new role altogether.


0

For me the trick was to add wp_ajax_nopriv action. I tested the script on one browser when I was logged in WP admin, and then I tried same script in Chrome and realized that the script doesn't work. After I put wp_ajax_nopriv, everything started to work. :) add_action( 'wp_ajax_nopriv_erase_uploaded_images', 'erase_uploaded_images' ); add_action( ...


0

To achieve something like that you can make some posts private and show them just to the logged in users, first you need to add a custom field, you can name it "private" and value it "True". Then add replace the default WP loop with this code snippet: <?php if (have_posts()) : while (have_posts()) : the_post(); $private = ...


0

Here you go.. add_action( 'gform_after_update_entry_7', 'add_length_on_update', 10, 2 ); function add_length_on_update( $form, $entry_id ) { if( !empty($_POST["input_3"]) && !empty($_POST["input_27"]) && !empty($_POST["input_28"]) ){ // get input from form $date = $_POST["input_3"]; $start = ...


2

human_time_difference() will not work here as it returns a string in a human readable form. However, we can use some of the logic used there to construct a workable function You can try the following: (Untested) function get_custom__time_diff() { global $post; // Get the current time $current_time = time(); // Get the post date ...


3

EDIT I have played around with a possible solution to your issue. We can try the following Add our own action to template_redirect where we do the following Check that the current request is a paged single post page and that we do not have the <!--nextpage--> tag in the post content. If everything checks out in our condition, we will do a manual ...


0

I tried to update the image size with: add_image_size( 'medium_large', 600, 255, array( 'center', 'top' ) ); But when i update the image size with height, width and crop, wordpress is just using the "large" image-size. When i just use add_image_size with the width argument: add_image_size('medium_large', 600, '', true); The image size gets updatet to ...


0

Norcross's example above is right on, but I needed the possibility of internationalization. If I had the reputation, this would be a comment under Norcross's answer, but since I don't, i'll just put the modified code here. 'i18n_context' is an arbitrary namespace for the translation context, this could be the name of your plugin or theme for example. ...


0

Hook the woocommerce_currency filter. function change_woocommerce_currency( $currency ) { if ( is_product_category( 'my-special-cat' ) ) { $currency = 'myCred' // or whatever the currency symbol is } return $currency; } add_filter( 'woocommerce_currency', 'change_woocommerce_currency' );


0

You can call add_image_size() again to update the existing image size. Assuming it is called medium_large (Events Manager Pro is a paid plugin so not very much people have it) you can do something like: <?php function update_medium_large_size_wpse216595() { add_image_size( 'medium_large', 600, 255, array( 'center', 'top' ) ); } add_action( 'init', ...


0

You need to close the PHP tag before you write html code for image source and then reopen the PHP tag once your HTML is finished. <?php function thumbImg() { if ( has_post_thumbnail() ) { the_post_thumbnail( array(54,54) ); } else { ?> <img src='<?php echo $data['featured_img']; ?>' alt='<?php the_title(); ...


3

You got it quite right, but with a few minor problems. First, please use a uniqe prefix for your functions and values - opacity or meta_save are quite generic and could be used by other authors. Second, the part where you get the meta opacity was missing, I added it for you - just retrieve the meta value from the current post. Third, I then created a ...


0

Just loop over WP_Query::$posts to get the titles: $option_posts = new WP_Query( [ 'post_type' => 'organisationer' ] ); $options = []; foreach ( $option_posts->posts as $post ) { $key = "option_{$post->ID}"; $options[ $key ] = apply_filters( 'the_title', $post->post_title ); } woocommerce_form_field_radio( 'custom_field', ...


0

As already mentioned in my comment above, there was not much information to work with. Assuming that a quick workaround using CSS code to overrule settings is enough, here a snippet which will hide the output as asked. Be aware that this will hide those CSS classes for the whole site. Add the snippet below at the end of your style.css in the folder ...


1

You need to recurse into the shortcode content ($m[5] as returned by get_shortcode_regex()), the standard way being to use preg_replace_callback(): public function wrapShortcode( $content ) { $content = preg_replace_callback( '/' . get_shortcode_regex() . '/s', array( $this, 'wrapShortcodeCallback' ), $content ); remove_filter( ...


0

By the time woocommerce_checkout_fields filter is run, the arrays for billing and shipping have already been created. You can see that here: https://docs.woothemes.com/wc-apidocs/source-class-WC_Checkout.html#101 If you want to effect the default fields, use this hook. function wpse215677_checkout_fields ( $fields ) { ...


0

The Cronjob Scheduler plugin allows you to run frequent tasks reliably and timely without anyone having to visit your site, all you need is at least 1 action and a Unix Crontab schedule. It's very easy to use, and very flexible. You create your own function, and define an action within it. Then you can choose your action from the plugin menu and fire it ...


2

You can create new schedule times via cron_schedules: function my_cron_schedules($schedules){ if(!isset($schedules["5min"])){ $schedules["5min"] = array( 'interval' => 5*60, 'display' => __('Once every 5 minutes')); } if(!isset($schedules["30min"])){ $schedules["30min"] = array( ...


0

Firest of all you have to make sure that is_page() is right. I think the right syntax is is_page( 'min-konto' ) or is_page($pageid) then the function should be if( is_page( $account_settings_page_id ) && is_user_logged_in() ) { wp_redirect( home_url( '/dashboard/' ) ); exit(); }


1

You are mixing html and php content. You should write it like this: <?php function thumbImg() { if ( has_post_thumbnail() ) { the_post_thumbnail( array(54,54) ); } else { echo "<img src='{$data['featured_img']}' alt='".get_the_title()."' />"; } } ?> This way, you don't need to open and close again the php tag.


5

You are returning inside your loop - so it returns on the first iteration, giving you one result only. You should build a string inside your loop instead, and only return when the loop is over. Something like $featured_properties = ''; if( $featured_query->have_posts() ): while( $featured_query->have_posts() ) : ...


0

If you're only concerned about login links displayed on your pages, you should be able to modify the URL by hooking the login_url filter. This won't redirect a user that types http://MYSITE/wp-login.php directly into their browser, but it should affect the login links displayed throughout your site. This is the example code from the Codex page: add_filter( ...


0

Create a blank page and name it panel then go to your created signup template and select parent page panel. Its just below Publish->Page Attributes. /*Add noindex to this page (Add to functions.php)*/ function add_noindex_tags(){ # Add noindex to page. if( is_page('panel') ) echo '<meta name="robots" content="noindex,nofollow">'; } ...


1

So I've found this WP_Image_Editor in the CodeX. Basically by adding the code below it should automatically resize an image :) Code: $image = wp_get_image_editor( 'cool_image.jpg' ); // Return an implementation that extends WP_Image_Editor if ( ! is_wp_error( $image ) ) { $image->resize( 300, 300, true ); $image->save( 'new_image.jpg' ); } ...


2

This is quite basic but should help you on your way. //Get posts for the current week $args = array( 'date_query' => array( array( 'year' => date( 'Y' ), 'week' => date( 'W' ), ) ) ); //Check for search query if ( isset( $_GET['s'] ) ) { $args['s'] = $_GET['s']; } //Create these variables for ...


0

If you want to remove the entire twentytwelve_scripts_styles function, you have to remove the action hook : remove_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); However, this code have to execute after the function is being hooked by Twenty Twelve code, and before the action is fired (because after it's too late). The child theme ...


1

You didn't specify how many arguments your function accepts when you used add_filter: add_filter( $tag, $function_to_add, $priority, $accepted_args ); Your code only passes a $tag and a $function_to_add, but it doesn't tell WordPress what priority it should be, or how many accepted arguments your function takes. You need to fix that. If you don't provide ...


0

You can use get_stylesheet_directory() to refer to your child theme, then you can point to your file. require_once( get_stylesheet_directory() . '/includes/theme-styles.php' ); It will load your file and replace the parent theme file.


2

The code you have provided is incomplete. Not sure if that is the only code you are using to achieve what you want. So, besides first code block which you have provided, bellow I am adding all rest of the code which is required to show the new field on backend in 'Order Details' box and make it editable through custom fields. Please note, in your second code ...


0

An important difference from the_content() is that get_the_content() does not pass the content through the 'the_content'. This means that get_the_content() will not auto-embed videos or expand shortcodes, among other things. If you find yourself annoyed with formatting of the content, more specifically the added p-tags that WordPress puts into the content ...


0

Our problem was that our style.css file was in a css folder inside the child theme directory, not at the root of the child theme. When we placed a style.css file at the root and included the comment block with theme name and template it picked up the functions.php file as expected.


1

At first - do not use extract. It's very bad code style and is also depracated in core. Every time your foreach loop run, you override content of $output because you assign to this variable new content. What you want is to concatenate new list item with existing ones. This can be done using concatening assignment operator: $output .= '<li ...


0

Ok, first I'd ditch the output buffering. Second change: include(TEMPLATEPATH.'/wp-content/themes/grainandmortar/inc_static/test.php'); To include( get_stylesheet_directory() . '/inc_static/test.php'); Finally, Reading the documentation here: https://codex.wordpress.org/Shortcode_API You need to return something, if your test.php doesn't output ...


1

Here's another way to do it, utilizing get_template_part of wordpress function include_file($atts) { $a = shortcode_atts( array( 'slug' => 'NULL', ), $atts ); if($slug != 'NULL'){ ob_start(); get_template_part($a['slug']); return ob_get_clean(); } } add_shortcode('include', 'include_file'); ...


0

I ended up inserting the payment description. (the one you specify in the woocommerce settings in the Wordpress backend) The "native" build-in woocommerce payment-text is static and doesn't relates to the actual selected payment method. :-( I did this by modifying the woocommerce template file: 1: Copy this template file: ...


5

This is more of a general srcset and browser question, not a WordPress specific question. However, in general, you can't predict what browsers will do with the srcset information. For your specific example, it appears that you failed to clear the cache completely between your reloads. Note the 304 response indicating that your browser already has the image ...


0

Double check you're using these functions correctly. Try collecting the results and output them in order to see what you're working with. get_the_ID() and get_queried_object_id() are two good ways to get the current ID, so pass them to get_post_status(). $debug = array ( 'get_the_ID' => get_the_ID(), 'get_the_ID_status' ...


0

There was an error in my code. From here: http://www.sitepoint.com/woocommerce-actions-and-filters-manipulate-cart/ Changing // correct quantity unset( $woocommerce->cart->cart_contents[$product_id] ); $woocommerce->cart->add_to_cart( $product_id, $quantity ); To // correct quantity // Get it's unique ID within the Cart $prod_unique_id = ...


0

upgrader_post_install has three parameters $response, $hook_extra and $result which give you extra information. At the moment I can't take a look myself, but I'm assuming that especially the $result variable should give you additional information to differentiate.


-2

You could remove it with jQuery this way: jQuery('.zoomthumbnail-image').next('br').remove();


2

Basic Filtering This is just a simple example and would work if you're just using it for editors that might slip up here or there and put in a swear word by accident. However, if you have to worry about people trying to "spoof" their words for example "focker, fuker, etc" then you'll probably need something more complex. // Basic Implementation function ...



Top 50 recent answers are included