Strip and print only the numbers found in current’s post excerpt (even if they are without space)

If you have a strict list of allowed years: $allowed_years = array(‘2018’, ‘2019’, ‘2020’, ‘2021’, ‘2022’, ‘2023’, ‘2024’); Then why are you using regex when you can search for those years directly: function vyperlook_get_years_in_text( string $text, array $allowed_years ) : array { $found_years = []; // the years we found // for each year that … Read more

SOLVED: Shortcode to display Divi project filtered by tag in WP Query loop

SOLUTION: I looked through Divi’s functions.php & saw that the term for the project tags is ‘project_tag’, so when I amended my $query args it now works! Thank you very much to everyone who responded 🙂 $query_args = array( ‘post_type’ => ‘project’, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘posts_per_page’ => ‘3’, ‘project_tag’ … Read more

Custom Field in Page Title

Use the wp_title filter, which passes the current title, separator, and location as arguments. It then appends the custom field value to the title if the conditions are meet. For more details :- Visit Link wp_title function wpse_224340_document_title($title, $sep, $seplocation) { global $post; // make sure the post object is available to us if (is_singular(‘mec-events’)) … Read more

Array to String Conversion warning in shortcode

You are getting that error because in the function parameter you are passing $content as 1st parameter but as per add_shortcode callback function it accepts 2 argument $atts – array $content – string It is basically trying to concat $atts param which is an array hence you are getting warning. Just update your code by … Read more

Show shortcode output in menu

Please add below line in your functions.php file add_filter(‘wp_nav_menu_items’, ‘do_shortcode’); This line will execute do_shortcode to your menu items and if there is any it will execute the shortcode.

Adding a css class to the gallery

If you look at the gallery shortcode you will see that you are using the wrong filter. With post_gallery you can override the complete html of the shortcode. Your code performs a str_replace on an empty string, resulting in an empty return and subsequently the generation of the default gallery html. Further on there is … Read more

Calling a function via a shortcode in javascript

I’m afraid the code you’ve shared is rather wonky and there isn’t just one thing that is backwards. Here are the first few things that came into my mind. add_filter( ‘learn-press/after-content-item-summary/lp_lesson’, ‘psb_comment_listener_func’); When you attach a callback function to a filter with add_filter, the callback should return a value. If the callback isn’t supposed to … Read more

php codes ruins shortcode structure

You need to change the_title() to get_the_title(). You are asking the shortcode to echo out a string that is returning the title. It would be good for you to research the difference between the_title and get_the_title. The main difference is that the_title is actually returning the title without any other requirement (this is simplified: there … Read more