How to call a function on particular page like ‘contact-us’ from function.php of child theme

The problem is that you’re trying to use is_page(), a conditional function intended only to run adjacent to the query, too early. Try running your code inside a callback that 1) only fires on the front-end, 2) fires after the page has partially loaded. For instance, wp_head. function prefix_run_on_contact_us() { if( is_page(‘contact-us’)) { echo “hello … Read more

wp_insert_posts keeps adding multiple pages

You can check whether the page exists or not, and create it only if it doesn’t already exist. get_page_by_title() can help you in this case: // Check if the page already exists if( ! get_page_by_title(‘My page Reql’) ) { // The page doesn’t exist, so let’s create it } Also, you might want to investigate … Read more

Passing arguments to my function with do_action and add_action is not working

You are doing the do_action before the action is add, try moving it: $name = “link”; add_shortcode($name, ‘aa_link_shortcode’); function shorcode_resources($var1) { global $post; $shortcode_found = false; if (has_shortcode($post->post_content, $var1)) { $shortcode_found = true; } if ($shortcode_found) { wp_enqueue_style(‘core’, ABS_URL . ‘/shortcode/css/flipbox.css’, false); wp_enqueue_script(‘my-js’, ABS_URL . ‘/shortcode/js/flipbox(‘ . $var1 . ‘).js’, false); } } //first we … Read more

Searching for content post

Stright from WordPress reference: https://developer.wordpress.org/reference/hooks/posts_search/#user-contributed-notes You can search by post title only with: function __search_by_title_only( $search, $wp_query ) { global $wpdb; if(empty($search)) { return $search; // skip processing – no search term in query } $q = $wp_query->query_vars; $n = !empty($q[‘exact’]) ? ” : ‘%’; $search = $searchand = ”; foreach ((array)$q[‘search_terms’] as $term) { … Read more

Logic to Print/echo a css class only for 1st post and ignore all post after 1st? [closed]

As I noted in the comments, this is more a programming language question than a WordPress Development question, and that goes for the second question, too. However, instead of adding to comment discussion and making more mistakes, I’ll write out an answer. function slider_news() { $num = 0; $args = array( ‘numberposts’ => 3 ); … Read more

Customizer field value into functions.php variable

Sure, every setting in the Customizer is saved either as a theme mod (by default) or option (if you set the ‘type’ to ‘option’ in $wp_customize->add_setting()). You can access the user-defined value using get_theme_mod() (or get_option()). In your example, the value you are looking for can be retrieved with: $downloads_tab_text = get_theme_mod( ‘product-downloads-tab’ );

How to use thumbnails in gallery?

There is a project going on about the image sizes. You can follow it right here. Right now, you can try using shortcode_atts_gallery filter. Take a look at these codes to get a hint: /* Register shortcode_atts_gallery filter callback */ add_filter( ‘shortcode_atts_gallery’, ‘meks_gallery_atts’, 10, 3 ); /* Change attributes of wp gallery to modify image … Read more