Hot answers tagged

2

There is no definitive way of doing that in WordPress, but here are some options for you: Use a global variable to store the reference list, i.e. the content as in [ref]content here[/ref]. But I personally don't recommend and wouldn't be using global variable. Use a custom PHP class and add the shortcode functions as methods in that class, then use a ...


2

You need to first get and check if there are any tags available, so something like this <?php if (get_tags()) : ?> <div class="etichete"> <p><?php the_tags(); ?></p> </div> <?php endif; ?> You can also use !empty(get_tags()) but because if no tags are available it will return an empty array and an ...


2

There are a few to do this: Using double quotes Don't forget to escape the double quotes inside the string. global $post; echo do_shortcode("[sc name=\"$post->post_name\"]"); Using sigle quotes global $post; echo do_shortcode("[sc name='$post->post_name']"); Using sprintf global $post; echo do_shortcode( sprintf('[sc ...


1

I changed it a little. But the code doesn't work for some reason :-( You should explain what exactly happened or did not happen that should have happened, rather than simply saying "doesn't work". But anyway, if the first and fifth lines below were the only changes you applied in the code: add_action( 'wp_insert_post_data', '...


1

You don't check anywhere that you're viewing a comment when you use get_comment_author();. The get_avatar() function is used in a lot of places in WordPress; your code seems to assume it's only in use on comments. Try this (the code is untested, but should work, I think): add_filter( 'get_avatar' , 'alt_name_avatar'); function alt_name_avatar( $avatar ) { ...


1

The best thing to do here is use the tools that WordPress has provided for you to construct your URLs. In this solution you're building an array of URL parameters with keys and values, then you're "attaching" these parameters to the array using add_query_arg. You can reuse this approach for all your URLs, and simply add/adjust your $parameters ...


1

Your checkbox data is saved as 1 or '' if someone checked or unchecked it. you can also verify this using var_dump($checkbox) inside custom_checkbox_field_html function This should work. function custom_checkbox_field_html(){ $checkbox = get_option( 'disabletitle_text' ); $is_checked = ( $checkbox != '' && $checkbox == 1 ) ? 'checked': ''; ...


1

Just replace your code with below one: @media only screen and (max-width: 900px) { .category .sidebar { display: none; } } if you want to hide in particular one category then use like this: @media only screen and (max-width: 900px) { .category.*category-slug* .sidebar { display: none; } }


1

add these lines in your 'functions.php', it will work //if not gutenberg reapprove posts add_filter( 'wp_insert_post_data', 're_aprove', '99', 2 ); function re_aprove( $data, $postarr ) { //check if current user is not admin if ( ! current_user_can( 'manage_options' ) ) { if ( 'publish' === $data['post_status'] ) { $data['...


1

Apply the following fixes (those with the // Fix <number>: comment) and your code would work in that only one random folder that will be created for all the uploads in the current session: (Note: I presumed the $countfiles is properly defined in your actual code.) function file_upload_callback() { global $wpdb; $table_name = '...


1

There are a few things omitted in the above solution, like defining the most params of wp_mail. Also I didn't want to send yet another concurrent email, but instead attach the csv directly to the mail that wpcf7 sends. I think this is the cleaner solution. Here's my take: add_filter( 'wpcf7_before_send_mail', 'add_form_as_attachment', 10, 3 ); function ...


1

The solutions here are all good but were not consistent with both local and remote server environments. So I came up with a simpler neat solution that works better regardless of the WordPress permalink settings. function getCurrentUrl() { $protocol = is_ssl() ? 'https://' : 'http://'; return ($protocol) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'...


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