Questions tagged [functions]

A function is a sequence of program instructions that perform a specific task. It is packaged as a unit that can be used wherever the according task should be performed.

Filter by
Sorted by
Tagged with
2 votes
6 answers
39k views

How to display post tags

I'm converting an HTML template into a wordpress theme and I'm having some trouble displaying the post tags within the functions.php file. What I would like to do is add the following code into the ...
0 votes
1 answer
2k views

How to get tags and categories?

I used the following code to get tags from the post and then simply echo them: $posttags = get_the_tags($post->ID); if ($posttags) { foreach($posttags as $tag) { echo $tag->name . ', ';} ...
0 votes
1 answer
1k views

How to display different blocks for mobile and desktops

I want to display a fixed banner from the bottom left of the screen. But at the same time, the banner is different for desktops and mobile devices. Please tell me. How can I determine the user's ...
0 votes
1 answer
1k views

Populate select option with JSON file

I am having a problem with populating a select dropdown from a JSON file. I am modifying an existing plugin, and I want to include countries that we want to see to. The JSON FILE { "AX": { "...
0 votes
0 answers
10 views

How Do I Prevent Featured Image Caption Displaying Above And Below Image

I'm trying to add an image caption below my featured image on my single posts. I have this working, but weirdly they are also displaying above the image. I'm hoping someone can help point out the ...
0 votes
1 answer
925 views

functions.php / replacing div's with new ones?

I'm not sure the best way to tackle this one: I have a menu I saw and like and want to use it as a basis for my own. I have the CSS for it. On the page it comes from its all labeled differently to my ...
0 votes
2 answers
731 views

Check if excerpt is empty at loop-portfolio

I want to check if excerpt is not empty, then echo the excerpt link, if not the echo permalink, like this: if(the_excerpt()!='') echo the_excerpt(); else echo get_permalink() but how can I check if ...
0 votes
1 answer
12 views

comments_template() doesn't work with ajax call

I want to load comments by ajax. I can't call comment_template() functions using an ajax request. I don't want create a new query because I'll lost all inherited args (like all settings option in the ...
0 votes
1 answer
23 views

Including product categories (product_cat taxonomy) title and description in search query

WHAT I'M TRYING TO DO I'm using woocommerce, but the question could work for WP categories also. When searching for a product, the search engine only looks for products info (title and description) ...
0 votes
1 answer
36 views

ENV for Wordpress

Hi im new to wordpress/php so apology in advance for such a noob question. Just a little bit of context, I'm trying to do this custom stripe payment integration on a wordpress site that does something ...
0 votes
1 answer
1k views

Work and Display a Custom Post Type as a normal Post

I've created some Custom Posts for my Wordpress page and I can work fine with them. I can create a new one, edit it and display it in "archive-custom_post_type_name.php" and many more things. I can ...
0 votes
2 answers
709 views

Could you please correct the code is_admin()

I have this code in my function.php: add_action( 'init', 'blockusers_init' ); function blockusers_init() { if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined(...
1 vote
1 answer
1k views

WordPress load javascript file if something... (after the page is loaded)

I'm having an issue with making a website GDPR ready. It is loading a javascript file for InstraGram that is setting a cookie. I was able to locate where this file is loaded in the plug-in directory ...
0 votes
2 answers
824 views

Redirect User Role When on Specific Page

I am trying to redirect user roles to a specific page. If their role is contributor and is trying to access the Users Admin Page they should be redirected. Not sure if I am doing this correctly as it ...
1 vote
2 answers
807 views

Get list of all custom tanonomy id

I created a custom taxonomy called Location then added New Jersey, New York, etc. Is there a Wordpress function that will get the list of all ids under the Location similar to what ...
0 votes
1 answer
980 views

Need to Echo A Url path to show on a wordpress page

I need to extract a url path number to a shortcode... Here is an example below... https://example.com/page/c/1 I need the number "1" to be shown with a shortcode... [url_path_number]
1 vote
1 answer
7k views

Max file size not updating

Hi I am a beginner at WordPress and am currently trying to increase my file upload size. So far I've tried two ways: The first way was to add this to the bottom of the functions.php file: @ini_set( ...
0 votes
1 answer
907 views

Soflyy WP All Import Custom File Download Issue

I need to send a user id to a remote server to download an XML file. I accomplish this with the snippet below: function custom_file_download($url, $type = 'xml'){ $ch = curl_init(); $...
1 vote
1 answer
16 views

Calling a PHP function from a menu item

Please forgive this totally newb question. I'm not a dev, and I'm a little too far that I can deal with right now... I'd like to add a link to the WooCommerce cart page using the cart icon from my ...
46 votes
4 answers
269k views

How to set and use global variables? Or why not to use them at all

UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was <?...
3 votes
2 answers
9k views

How can I load a javascript file that is type="module" the Wordpress way?

Typically, when I am going to load javascript files I load them from my functions.php file using this code: wp_deregister_script('site-js'); wp_register_script('site-js', ...
1 vote
1 answer
981 views

Firing schema via code in functions.php doesn't work

I've been banging my head against the wall trying to get schema figured out, so if anyone can help me, I'd appreciate it greatly. I'm trying to manually add my schema via custom fields, and then ...
0 votes
3 answers
2k views

Show only top 3 posts from 3 categories in order on home page

This function will show the last 3 posts from any category on front page: // Only top 3 posts from CHR category add_action('pre_get_posts', 'ad_filter_categories'); function ...
1 vote
1 answer
12 views

Options of select field in a custom divi module ignore sorting

I made a little custom module for the Divi Builder which allows me to display a specific single post (from a custom post type). This works fine, but the options are not sorted correctly in the builder,...
0 votes
1 answer
709 views

How to add meta fields to custom taxonomy add/edit page?

I have a custom taxonomy 'issue'. I tried to add some meta fields to the add/edit issue pages in the dashboard using the method explained by Ohad Raz (https://en.bainternet.info/wordpress-taxonomies-...
0 votes
1 answer
2k views

WP Ajax Function Always Returning undefined

What is the deal here? JS FUNCTION 'custom.js' function validate() { var email = jQuery("#billingemail").val(); if (isValidEmailAddress(email)) { jQuery.ajax({ ...
0 votes
2 answers
733 views

Gravity Forms: How to add PHP function to confirmation conditional shortcode?

In Gravity Forms, I have a confirmation set up with various conditional shortcodes. Example: [gravityforms action="conditional" merge_tag="{:3:value}" condition="contains"...
0 votes
2 answers
3k views

How to override filter in child theme?

I'm trying to override a parent theme filter in a child theme; I must have the syntax wrong as the override is being completely ignored. Here's what's in my child theme's functions.php: //* remove ...
1 vote
1 answer
7k views

How to add widget in main menu

I want to display widgets in main menu. There are few plugins to do this and i already used in my previous projects. But now i want do without any plugin. I can create a custom sidebar and call this ...
0 votes
1 answer
1k views

custom COOKIE on custom page

i have problem with create function for set cookie dynamically. when i try in custom page i have of course header is set and i tried something like this: in custompage.php: myfunction($cookiename,$...
0 votes
2 answers
777 views

Insert Modal on user first login

Attempting to create a Welcome Modal for first time users on initial login to my Multisite network. I'm using code from this tutorial https://wp-mix.com/wordpress-first-user-login/ I can see the User ...
0 votes
1 answer
720 views

Remove pagination if search returns empty

I made a fix that when the searchbar is empty, it returns 'No results', instead of all posts, but the pagination still shows up. Does anyone know a fix for that? My code search.php: <div class="...
16 votes
7 answers
40k views

How to check if a user exists by a given id

Is there any way to check if a user id exists? I want to create a function similar to username_exists() but which returns if the id exists or not.
0 votes
1 answer
3k views

How to automatically add custom classes to headings in content area

Is there any way I can automatically add a custom class to heading tags (like h1, h2, h3, etc..,) in the content area. I know that I can manually add a class to a sub-heading from the post editor, but ...
1 vote
0 answers
12 views

Custom update for Woocommerce stock quantity [closed]

In my Wordpress store, products are set as simple, but I use WS Form to add attributes to the product/order. We sell travels packages. When a user purchase a product, the quantity decrease to 1. But ...
0 votes
2 answers
901 views

how can I change all wordpress media file url to custom cdn url?

any function can apply change all image URLs to CDN instead of modifying media.php in wp-includes folder ?
0 votes
3 answers
3k views

Show custom default avatar instead of gravatar

I'm using this custom function to get the default avatar from my server instead of gravatar: if(!function_exists('custom_avatar')){ function custom_avatar($avatar_defaults){ $...
0 votes
2 answers
854 views

Remove generated category and tag class names from woocommerce product & blog listings markup

I noticed in my wordpress/woocommerce setup that every time i add a tag to a product or a blog post. It adds that tag as a class into the listed item (Product/blog) I also noticed it adds a class in ...
0 votes
2 answers
739 views

Display text of price (minus 20%) on every product page in a sentence.

We have loads of products on our woo commerce and are trying to automate a few things. All our products are 20% off if you use our specific promo code. So at the top of every product page there is a ...
0 votes
0 answers
21 views

get last part of page url and add it as cat in wp_query

I have a page URL : https://mwallpaper.ir/mobile-wallpapers/birds and I grabbed last part of URL with this filter : add_filter( 'example_filter', 'catslug_callback' ); function catslug_callback( $...
1 vote
1 answer
811 views

How to display custom option field in woocommerce orders in admin panel?

Actually this question has already answered as i already checked but i am unable to comment on that question as i am using the same code but in my scenario i am using options field and value is not ...
0 votes
2 answers
1k views

Can I use a function to return HTML and the result of another function?

I have a very simple function to create a shortcode to get the name of my page. I was using this shortcode in a form, but WordPress changed the Shortcode API and that no longer works. So I was ...
1 vote
0 answers
14 views

How can I restrict comments on Wordpress, so only the POST AUTHOR and the user who commented can see them?

I'm after a way to hide / restrict FRONTEND comments on Wordpress posts, so that only the post Author can see them, as well as the user who posted the comment? Eg - Bob creates a post, and Sally, ...
0 votes
1 answer
2k views

Populate custom post type/custom fields from an external database

I have a custom MySQL DB(same host/different domain) with a lot of vehicle information. What we want to do is populate a custom post type and custom fields with this data so that it's SEO friendly in ...
0 votes
2 answers
2k views

How to disable controls in theme customizer?

Edit: I have rewritten the question in hopes I will get a reply from someone who knows the theme customizer. I am trying to figure out how to disable setting controls in the Wordpress theme ...
0 votes
1 answer
733 views

How to replace words in my posts and saved new words

i need replace words in my posts and saved new words after delete code in my functions i use this code for replace <?php function replace_text_wps($text){ $replace = array( // ‘WORD TO REPLACE’ =...
1 vote
2 answers
1k views

How to pick the default selected value in wordpress dropdown?

First of I am pretty new to this so sorry if this has been asked before but I could not find the right answer for me. I have this dropdown on my website from compare-tech(.)fr I am trying to remove ...
0 votes
1 answer
1k views

Custom global variable not working in function

I've been stumped on this for a while and cannot for the life of me figure out why my function isn't able to reference my global variable. $query_obj = get_queried_object(); if ( is_a($query_obj, '...
1 vote
0 answers
19 views

Trying to insert widget code into theme function

The site I am working on has a function in the theme (Botiga) that creates a wrapper row that displays a sorting dropdown for the items below. The default output is the dropdown displays in the right ...
0 votes
1 answer
787 views

WordPress not showing pagination links

In my WordPress Index.html I am pulling out the 3 latest posts by using <?php query_posts('posts_per_page=3') ?> <?php while(have_posts()) : the_post(); ?> //rest of the post related ...

1
2 3 4 5
115