Articles of functions

Fallback image URL if no featured image exists via a shortcode function

What I’m trying to do is add a fallback image to this shortcode function that grabs the featured image to account for the possibility that a post has no featured image. (This function creates a shortcode because I need to use that within another plugin that requires the shortcode to generate HTML display.) I’ve read […]

Add loggedout class on body using a function or JS

Is it possible to add a class loggedout on the body of every page for all logged out users using a function or JS? My theme already adds a class ‘loggedin’ for all logged in users.

How to modify get_the_excerpt() when post-format equals 'quote'?

How can I modify the get_the_excerpt() when the post-format of the post is set to quote?

Overwriting a plugin function

I need to write a function in my own plugin and overwrite a function from another plugin and (preferably) not make any changes to it. Or WordPress’ core. So, basically, what I need to happen is: plugin X do it’s work, it’s time for function Y to do something, and instead of X’s Y function, […]

Disabling visual editor on a specific post

I would like to disable the visual editor for post id 416 on my local WordPress installation, to do so (following this answer) I added: add_filter( ‘user_can_richedit’, ‘wpse_58501_page_can_richedit’ ); function wpse_58501_page_can_richedit( $can ) { global $post; if ( 416 == $post->ID ) return false; return $can; } at the end (just before the end curly […]

Change WooCommerce add_to_cart Button Text?

I am trying to change the add_to_cart button text for all products based on category. For category ‘course’ with ID 330, I would like the button to read ‘Register’. For all other products, I would like it to read ‘Buy Now’. Here is what I have thus far in my functions.php: add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘custom_cat_add_to_cart_text’ ); […]

Is this an acceptable practice for WordPress theme development?

I don’t think this is the right way to do things, maybe I’m wrong or missing something but to me it seems unnecessary. Is this correct? What are the implications if any of doing things this way? In the functions file all the functions are wrapped in a class: class This_Theme { function example_fucntion( echo […]

How to use wp_list_categories with plugin category?

Attempting to use: <?php wp_list_categories( $args ); ?> And this works fine to display a list of the default WordPress category group used for posts(?) but I’m looking to pull a category group that is created by a plugin. Is there a parameter I can pass above that will pull a different group or can […]

Fail to get the total number of posts

I would like to get the total number of posts by the following code: <?php $published_posts = wp_count_posts()->publish; echo ‘Total posts: ‘; $published_posts; ?> The result is Total posts: without followed by a number.

Function not saving unchecked checkbox

I’m trying to save custom option for taxonomies in wp_options. The following function saves the post id in array if checkbox is checked but when I uncheck the checkbox it doesn’t removes term id from wp_options. function wpfs_save_tax($term_id) { $featured_tax = get_option(‘_featured_tax’); if(empty($featured_tax) ) { $featured_tax = array(); } if (isset($_POST[‘wpfs_tax’])) { if(!in_array($term_id, $featured_tax) ) […]