Adding `post_author` in php
Try this <div class=”my_edit_button”> <?php if ( $post->post_author == $current_user->ID ) { echo do_shortcode(‘[something]’); }?> </div>
Try this <div class=”my_edit_button”> <?php if ( $post->post_author == $current_user->ID ) { echo do_shortcode(‘[something]’); }?> </div>
<?php class someClass { public function __construct($options = null, $initialize = true, $error_messages = null, $path, $qnty) { //construct what you see fit here…. } //etc.. } // Action listener add_action( ‘action_name’, create_function(”, “new someClass(implode(‘,’,func_get_args()));”), 10, 5 // IMPORTANT, number of arguments your construct function accept ); // Call the action $options = “options”; $initialize … Read more
Add to your functions file and use wp_nav_menu_items add_filter(‘wp_nav_menu_items’,’wpsites_add_avatar_to_nav’, 10, 2); function wpsites_add_avatar_to_nav( $items, $args ) { if( $args->theme_location == ‘primary’ ) return $items; $dude = get_avatar( get_current_user_id(), 48 ); if (is_user_logged_in()) : echo'<li class=”your-custom-class right”>’ . $dude . ‘</li>’; endif; return $items; } Might need to use output buffering. Some work is required on … Read more
It’s the text domain, used for translation. When you run something like this: <?php _e( ‘Hello World’, ‘html5blank’ ) ?> …WordPress will attempt to find the translated string in the loaded MO file for HTML5 Blank: load_theme_textdomain( ‘html5blank’, ‘path/to/language.mo’ );
Use the_title_attribute() to print the attribute. A post title might contain HTML, so you need the escaped content that this function returns. Also suppress immediate print-out, because that will set the output in front of the echo statement. if ( is_singular( ‘communications’ ) ) { $title = the_title_attribute( [ ‘echo’ => FALSE ] ); echo … Read more
You need to use the woocommerce_get_price filter: add_filter(‘woocommerce_get_price’, ‘return_custom_price’, $product, 2); function return_custom_price($price, $product) { global $post, $woocommerce; // Array containing country codes $county = array(‘CH’); // Amount to increase by $amount = 5; // If the custromers shipping country is in the array if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ){ // Return the price … Read more
You can use the logged-in class added by body_class to target your CSS rules. .container { height: 160px } body.logged-in .container { height: 30px }
I’d recommend moving this to a plugin, rather than doing it in the theme, and then activating it on the main site. The rule that I follow is that if it’s going to affect the look, it goes in the theme; if it’s affecting functionality, then it goes in a plugin. This, to my mind, … Read more
Note that it might be easier to use get_comments() here, since it’s defined as: function get_comments( $args=”” ) { $query = new WP_Comment_Query; return $query->query( $args ); } If you need the comment url, within your foreach comment loop, you can use: $comment_url = esc_url( get_comment_link( $comment ) ); You can also get the post … Read more
The Codex ( or Developer Resources ) is a fantastic tool when you’re unsure about a function. Looking at the parameter list for the_date() it says: the_date( $format, $before, $after, $echo ); So you need to pass in a format as the first parameter, then your HTML tags like you have it. An example could … Read more