Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
25 views

How to modify the code to include “rel=next” and “rel=prev” tags?

I have a Wordpress site with some posts splitted in pages. I added post pagination via this code: Single.php: <?php wp_link_pages(array( 'before' => '<div class="page-links"><span ...
1
vote
0answers
28 views

Make Categories a Dropdown Menu in Media Library

I would like the categories menu to appear as a drop-down in both the list mode and grid mode view of the Wordpress media library. As of now, it only appears as a drop-down in list mode. List Mode - ...
0
votes
0answers
70 views

How do I make comment-reply-button with <span> that takes to comment reply form on click

I do need your help. I'm actually designing my personal blog's theme and I got stuck when I could not code a working comment-reply-button with span element. I know you must be wondering why with a ...
0
votes
0answers
21 views

Menu and category highlighting for a single post

I use custom page menus and category list. The theme I use includes css styles to highlight the menu and archive. My goal is to highlight them for a single post. For example, the link structure I use ...
0
votes
0answers
14 views

Removing a specific script and loading my own in wp-admin

How can I create a function to remove a specific script src? Example: /blog/blog/wp-includes/js/tinymce/tinymce.min.js?ver=4800-20180716 To be replaced with: /blog/wp-includes/js/tinymce/tinymce....
1
vote
1answer
50 views

How do I create comment-reply-button using <span> element not <a>

I'm currently working to design my first WordPress blog and I got stuck when I came to code comment-reply-button because I want the comment-reply-button to be coded in span element only not a element ...
-1
votes
0answers
23 views

Wp function > Shortcode with SQL Query

I have the following problem I have a DB with information like sku/gtin, price, url, name... now I try to create a shortcode which selects the data based on one sku my Code is function ...
0
votes
0answers
16 views

How to upload 3 attachments to current post?

I have a form which updates a post but when updating I need to be able to also upload 3 posts: <div class="form-group"> <input class="form-control" type="file" tabindex="3" name="custom-...
0
votes
0answers
15 views

Load Disqus comments after clicking a button

I have an official Disqus plugin installed on my site. However, I would like to load the comments only after user clicks on a button - "Load comments" for example. Comments should remain hidden until ...
0
votes
1answer
18 views

locking content with overlay/pop up ads

how can i add a pop up before content or before downloading files ?i want to show a custom ad pop up (with option to close ad-similar to what you see in ad.fly url shortener) before a file download /...
0
votes
0answers
7 views

Menu to the right of screen on desktop using Bootstrap 4

I'm fairly new to WordPress development and would love to learn as much as possible. I am building a theme from scratch and using the wp-bootstrap-navwalker (https://github.com/wp-bootstrap/wp-...
5
votes
2answers
286 views

What’s the difference between esc_html, esc_attr, esc_html_e, and so on?

I got feedback from security guy and he pointed out that I should use proper escaping of user input in my code. So I've done some research and found escaping functions. What’s the difference between ...
1
vote
1answer
20 views

Members only site - still need the lost password page accessible

My site requires login before viewing any page and it works great: function wpse_131562_redirect() { if ( !is_user_logged_in() ) {auth_redirect(); }} add_action('template_redirect', '...
2
votes
0answers
88 views

Override woocommerce wc-class function

I'm not good in WP and plugins and will need some help here. I've read that is possible to alter some WC core function with filters and action but probably I didn't understand this correctly. I want ...
0
votes
1answer
19 views

Detect what link user clicks and Redirect to a specific page for logged in users only

I have a link in my WP website Account link. I would like this to work normally for logged out users. However for Logged-in users i would like this link to take them to another page url. I have tried:...
0
votes
0answers
39 views

“Conditional query tags do not work before the query is run. Before > then, they always return false. ”

I'm getting the following error Notice: is_tax was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging ...
0
votes
1answer
56 views

WP_Query To Display Product Of Brand On Taxonomy Page

I am trying to print all products of a brand on a taxonomy page. I find the wp_querry but i cant print the current brand name of the brand to show all products in this page. What to put on terms ...
0
votes
1answer
22 views

Post source link plugin - small modification

I'm using a little plugin that allows me to add source link to every article. I found the code in this thread: Article source link for posts It's almost perfect, but I need to make 2 little ...
-1
votes
0answers
34 views

enqueue script adds another .css with same name?

First I apologize if I'm not clear but I'll try to explain my problem with my enqueue script. I am trying to build a WP theme (conveting HTML & CSS Website) with existing files, but when I try to ...
0
votes
1answer
57 views

How to use `foreach()` in ajax call

I have written a code for retrieving data from the database using the ajax for WordPress. The following code is the one written in the functions.php. The code is for getting the id and names of ...
0
votes
1answer
22 views

Change 'Categories' to 'Topics'

I'm trying to find a way of displaying 'Topics' rather than 'Categories' and so far not being very successful. I tried this: function translate_category($translated) { $translated = str_ireplace('...
1
vote
1answer
41 views

'is' functions and 'get_query_var' not working

Why does is functions not work inside an Ajax function? Except for is_user_logged_in? I also tried using get_query_var and it did not work. jQuery: jQuery('.post-modal').live('click', function(e) { ...
1
vote
1answer
36 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
0answers
13 views

Woocommerce Add custom “Add to cart button” in single page with tags

I want to add a custom "ADD TO CART" button in the single product page. I have done it using the id of the product. <?php echo '<a href="?add-to-cart='.get_the_id($product_id).'">ADD TO ...
0
votes
2answers
31 views

Setting a cookie upon specific URL visit

I'm trying to set up, when a specific page/url is visited that a cookie is set and saved. So far I've tried this: add_action('init', 'set_cookie', 1); function set_cookie(){ if ( $currentURL == '...
0
votes
0answers
26 views

Remove action hook from Class, understanding OOP

I am trying to remove an action that is within a class, of the parent theme. I made an example of the code I have, below. I am trying to remove the action in the child theme functions.php. I've tried ...
0
votes
1answer
19 views

WP_CRON issue with UTC and local time

I have made a plugin to change some user metadata on a schedule according to the wp_cron function. If the current time is say between their lunch hours (that is in their user profile as date('g:i a', ...
1
vote
2answers
62 views

Checking is user author of number of posts?

I have this function... $user = wp_get_current_user(); if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) { /* Is subscriber, is in category Locked, has ...
1
vote
2answers
138 views

Proper way of using functions in action hook?

I am wondering if the below logic is correct and if certain circumstances should be present for it to work, since in some cases it does not seem to be working. The example below is quite simple. Let'...
0
votes
0answers
82 views

Offset with ajax load more posts duplicates

I have a shortcode that gets posts. I am using the shortcode three times on the page. The first time I grab the first 6 posts, the second time I offset by 6 and grab the next 4 posts, the third time I ...
0
votes
0answers
29 views

CSS disabled after getting rid of emoji

I created custom theme in Wordpress and wanted to apply it to my site. Apparently, in the header section, besides the elements, weird text about emoji appeared. I found out that I have to turn out the ...
1
vote
1answer
59 views

How do I use <picture> element instead of <img> tags in WordPress post content having webP support?

I am developing my custom theme and trying to figure out how to modify the default code for WordPress image inserted into the post content, so I could add support for webP format and have it within &...
0
votes
1answer
20 views

Is admin section completely customizable in terms of styling?

Can we completely customize the WordPress dashboard in terms of appearance and style? I have uploaded the image: Or Wordpress doesn't allow such conversions. I mean the right-hand side part shown ...
0
votes
1answer
18 views

Auto copy value from specific user meta field to another field

I'm looking for synchronizing specific user meta field with another one. ex: Coping user phone number to woocommerce billing phone. So the admin can only edit one field and the other updates ...
0
votes
1answer
34 views

Wordpress 302 Redirect to Random Product/Post/Page

I'm trying to add the ability to redirect a user to a random product/page/post url similar to example.com/page/random which would redirect to example.com/page/oneofmany. This question is not ...
0
votes
1answer
8 views

How to get correct value from checked()?

I am trying to create 2 raido buttons as a category custom field, and in function.php I do: $feat = get_term_meta( $tag->term_id, '_feat', true ); <input name="feat" type="radio" value="0" &...
-1
votes
0answers
11 views

How can I get postal using GeoIP?

WooCommerce: 3.5.1 WordPress: 4.9.8 GeoIP Detection plugin 2.9.1 https://ru.wordpress.org/plugins/geoip-detect/ I need to set the postal code value from GeoIP into billing or shipping fields in ...
0
votes
1answer
20 views

How can I pass a shortcode value to the head in wordpress functions.php

I'm trying to create a shortcode for charts on wordpress posts. So far I've got the shortcode working and I can see the shortcode values are being passed through, but what I need to know is how to ...
-1
votes
0answers
42 views

How to override parent function $title in child theme

I made a child theme and want to override some text produced by a function but i am not sure how to do it or where to put the code in my child theme directory. Original: $title = __('Recent Posts', '...
-1
votes
0answers
31 views

Add Cart Item meta data based on other items

I use the following function to show the discount in the cart if a product in the cart is on sale: function my_custom_show_sale_price_at_cart( $old_display, $cart_item, $cart_item_key ) { /** @...
0
votes
3answers
37 views

static array on functions.php

In functions.php, I want to access the DB once to get an ACF object, and then "save" it locally to prevent further requests to the DB. I thought of first calling the following function in the "init' ...
0
votes
2answers
41 views

Cant display an image via PHP in wordpress

I have a strange problem, when I try to enter the source of an image tag using PHP it shows me the following error in the inspector <img src=(unknown) alt=""> this code fragment gives me the ...
-1
votes
0answers
9 views

Create a default parents for children pages that have the same parent in the menu

Here's my problem: I'm building a website and my goal is to create a nice menu that will interact with the pages. So far so good, except for one problem. The structure of my menu is something like ...
0
votes
0answers
20 views

Ajax Cross-sell optional extras below single product description

Screenshot below isn't Woocommerce, but id like to replicate the functionality of the "optional extras". What is the best way to accomplish this? Having a list form of "cross sell" products under ...
0
votes
3answers
67 views

How do I create a child theme from PowerMag theme

I am using PowerMag 2.5 as parent and can't seem to find a way to get a working child theme. As far as I am now, I can only extend css in the style.css but as far as overriding, nothing has worked. ...
-1
votes
0answers
28 views

Pagination in shortcode not working

I got a shortcode that displays a loop of posts with pagination. My problem is I can seem to make the pagination work. Although the URL changes but the list of the page is not working. function ...
0
votes
3answers
60 views

Adding Gravity Form With if(is_page) Is Not Working

Please bear with me as I am a front-end developer trying to grapple with PHP. I am attempting to add a gravity form to specific pages on my website website by adding a function to my functions.php ...
1
vote
3answers
64 views

How can I change the do_action function in footer (copyright area)

Theme: Education LMS How can I remove the theme information from my footer copyright area, or how can I edit the do_action function? So that only display what I want to display in footer. ...
0
votes
1answer
33 views

Cross origin ajax request always returns 0 when calling get_current_user_id();

I currently work on localhost and when I want to test ajax requests to my web server, the function get_current_user_id() always returns 0. When I make the ajax request from my website however, it ...
1
vote
1answer
20 views

Is possible add icon in title posts only in specific tag?

I want to add an icon in title posts only in posts with specific tag. Is this possible? I've already tried these codes, but they didn't solve my problem: Approach #1 if (is_tag('162')) { ...