Stack Exchange Network

Stack Exchange network consists of 175 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
1answer
51 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
21 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')) { ...
2
votes
1answer
188 views

How to call WordPress functions from a form processing script

I'm working on a plugin which submits data via a form from a custom admin page. This is a simplified version of my form: <form action="<?php echo plugin_dir_path(); ?>/process.php" method="...
0
votes
1answer
645 views

Download PDF after CF7 form submission

I'm working on a client's build, and I'd like to change as little as possible. I'm not too familiar with all this, my apologies - I'll try to show where I'm at. The client wants a form submission to ...
-1
votes
1answer
628 views

Notice: Use of undefined constant REQUEST_URI - assumed 'REQUEST_URI' in …functions.php on line 73

When I tried to edit my menu, it appeared HTTP ERROR 500 Then I set define('WP_DEBUG', true); in wp-config.php Once I try to save the menu, the following error appears: Notice: Use of ...
0
votes
0answers
16 views

Variable function names

I am working on a plugin that will add messages to a WooCommerce product at set places on a single item/product page and run into an issue that to be honest I have never needed a requirement for in ...
0
votes
1answer
19 views

how to change “posted by” words

How do I change the words "posted by" and "on" that show on top of each WP post, to my own language? For example I want to change this: Posted by محمد on 6 نوفمبر 2018, 12:22 م to: كتبه محمد في 6 ...
0
votes
0answers
50 views

Set custom form limit-entries Gravity Forms

i am trying to limit a Gravity Form in my WordPress project by a custom field. This field, which is an ACF field like others on the same page, only calls a number. I am trying to overwrite the field "...
0
votes
1answer
117 views

Co-Authors Plus: How do I get all authors with a query?

I've recently installed the Co-Authors Plus plugin and am trying to get all the authors from a post within a post loop. However for some reason when I use get_queried_object(), there is only one ...
1
vote
1answer
216 views

Shortcode returns escaped HTML tags

To put things in context, I'm using Gantry on WordPress, which is bundled with Timber and Twig. I have this code, basic, make-your-text-bold shortcode // Add Shortcode function bold_text_shortcode( $...
2
votes
2answers
26 views

Display only custom post type count for current author on the “At a Glance” dashboard widget

I am using this code to display all custom post types along with their count on the "At a Glance" dashboard widget: add_action( 'dashboard_glance_items', 'cpad_at_glance_content_table_end' ); ...
0
votes
1answer
20 views

Load custom post type with ID in a shortcode

I develop a theme for the first time. I created a custom post type for banners/call to actions that I want to include in different posts with a shortcode. The shortcode should look like [banner id=123]...
0
votes
1answer
19 views

Add_filter when value is no variable?

Let's say I have an function like: function cc_get_content_preview() { return apply_filters( 'cc_get_content_preview', get_the_excerpt(), 55 ); } Here get_the_excerpt() is the $value that I can ...
0
votes
1answer
29 views

Template Loop - add switch case php

My plugin template is currently as follows: if ( $query->have_posts() ) { ?> <ul id="list-con"> <?php while ($query->have_posts()) { $query->the_post();...
0
votes
1answer
54 views

Add parent menu item in sub-menu in custom nav_walker

Currently I'm working on a project where we need to append the parent title as first item in the submenu for a mobile menu. What I try to achieve is this: <ul class="menu"> <li> ...
0
votes
1answer
9 views

Change default color scheme in twentyfifteen child theme?

I read the previous ask about this. And tried renaming my scheme to "default" and it didn't work. I am implementing the child theme on 50+ blogs on a network and I would like to just click "Activate" ...
0
votes
1answer
23 views

Remove Custom Divs from AMP pages

I am using Automattic's plugin to implement AMP on my website. Currently, to make my videos responsive, I wrap YouTube videos around a custom div. So, a YouTube video on my website looks like this:- &...
0
votes
0answers
10 views

Redirect Search link to specific Category search

I simply want to redirect all search link on my post to custom category search. E.g I have a category named WordPress, and content of the posts on that category already contains links to search ...
0
votes
0answers
17 views

Search by Category With Custom Search

Please help me out, Is there any way I can make a custom wp search to work on category? already I have a custom search with /search/ permalink. But it does not work on category it only works on ...
2
votes
1answer
58 views

Best practice custom function, where to echo the variables?

I have a custom function to query some posts. I was wondering if it is okay to echo variables within the loop of the function, since normally I would echo a variable at the end of the function. If so, ...
0
votes
1answer
21 views

Return function results within shortcode

I'm trying to write reusable functions in a plugin and call the functions within a shortcode. But, I can't get any output. Why don't either of these methods work? <?php function say_sup(){...
0
votes
0answers
18 views

Is there any function to get form submit value with default value?

Is there any Wordpress function to replace this code? <?php $page = isset($_POST['page']) ? $_POST['page'] : 1; I would like to replace isset($_POST['page']) ? $_POST['page'] : 1; to a easy ...
0
votes
0answers
28 views

Wordpress Toggle Menu has stopped working

I am using the twentyfifteen theme on my wordpress site. When you access the site on mobile or resize on your browser so that the page height > width, a hamburger icon appears on the upper right. I ...
0
votes
1answer
26 views

Restrict access if logged out except for homepage

I want to retrict access to my whole wordpress except for the homepage and one other page. The problem I found is that the other page is accessible but not the homepage. My wordpress installation is ...
0
votes
1answer
50 views

Why is wp_list_authors not picking up Authors from CPT's?

Why is wp_list_authors not picking up Authors from CPT's when I have the supports option enabled? From what I have read elsewhere it looks like I have everything covered but the authors of CPT's ...
0
votes
1answer
31 views

Using custom fields for image alt and title

I've Add a custom field to my products editing page with ACF. Custom field name is my_seo_title ; Each product has a unique SEO Title. How can I use this field as an alt text and title for images in ...
0
votes
0answers
25 views

Add meta data in head from theme

I want to add a meta data in the head of my website. I have a post type with custom template : single-custom.php In this template, I want to add this meta : <meta name="robots" content="noindex"&...
0
votes
1answer
25 views

Add attribute only to first image of every post via functions.php

I would like to use a simple function in order to add a specific attribute (lets call it “example”) to the first image of every blog post, so that I don't have to do it manually in thousands of posts. ...
1
vote
1answer
32 views

Shortcode created to check language not works

i need to create a shortcode to display a different Div depending on WP current language only when users are logout. The shortcode is this one: function coupon_box() { $user = is_user_logged_in() ; ...
0
votes
3answers
115 views

Get user custom field value on function.php

I created a function in function.php which send an email with user information at registration. I succeed to get the ID but I can't get custom fields... I only can get these ones : - ID - ...
0
votes
0answers
30 views

Why is the term of my current page not returning a slug?

Why is the term of my current page (custom taxonomy) not returning a slug? I have managed to get the following returned in my URL: 0, Array, '/{empty space}/ I am trying to pass the custom taxonomy ...
0
votes
0answers
23 views

How to style Image and Gallery Output for AMP?

So, I am trying to create a custom AMP template for my website without a plugin. Here's where the problem is. I am using a single-amp.php to redirect /amp posts to the AMP template. I have then used a ...
0
votes
1answer
19 views

Change Search display for Custom Post Type

I want the search to not search for custom post type "mitgliederbereich" when on other pages, and when you are on the "mitgliederbereich" page, that only "mitgliederbereich" posts should appear in ...
0
votes
1answer
53 views

Create New User Custom Field not Saving

I've added a function to my child-theme to add a new field in the Add New User section so that you can select if the member is either just a member or candidate etc : function ...
0
votes
1answer
17 views

Do I need to use wp_reset_postdata for my function?

I am using this function which seems to work fine, however I was wondering if I must use wp_reset_postdata after endwhile? function evecal_task_function() { $args=array( 'posts_per_page' => -1, ...
0
votes
1answer
23 views

custom post type column countdown

i have registered custom post type and i have created custom columns for it one of those columns is count down it's functionality to cut the NowTime from the custom meta date and time i have set ...
0
votes
0answers
65 views

ajaxurl usage for a custom function

I am creating a custom form in one of my paste and its getting submitted using AJAX post method. Here is my code: HTML for button : <button onclick="result()" type="button" name="result_submit" ...
0
votes
0answers
42 views

Wp_schedule_event functions.php

I am using this code in my functions.php which works fine. However, I was wondering if this is the best practice to do so to schedule an event, or if there is a better solution. if (!...
0
votes
0answers
76 views

Woocommerce endpoint titles in my account template

I am working with woo-commerce user dashboard template. I need to print the title of current endpoint instead of the_title();. following image snapshot of DOMIAN.com/my-account/orders/. there should ...
1
vote
1answer
52 views

How to display post content instead of excerpt

I am using a plugin, and to get around something I need to add some text to the excerpt field on my posts, but I don't want to display the excerpt field data on the front end, but rather the post ...
0
votes
1answer
32 views

How to add styles in existing function?

The goal is to add some internal styles to a function. The function has some if statements, and then it does: $content .= " <div> <h3>stuff</h3> <div>$additional_stuff&...
1
vote
1answer
34 views

Two Types of settings in WP - The Doubt

I was trying to learn some basics of wordpress plugin development, and I stumbled upon two types of settings. 1 add_settings_field( 'custom_title', esc_html__('Custom Title', 'myplugin'), ...
0
votes
1answer
23 views

deactivating an active plugin using if page

Good day! just wondering if you can help me out? I was trying to create a code for functions.php if the user currently lands on a specific page, thus the plugin will turn deactivated, but if the user ...
1
vote
1answer
30 views

Add function to every post?

I have some code that generates a dropdown list of all my post files. I would like to add this dropdown to the top of every post page, right before the post content. What's the correct hook/action ...
1
vote
3answers
30 views

Using separate .php file for functions - how to run on site?

Instead of bogging down my child theme's functions.php file, I would like to have a separate .php file that has various functions, that I can call within functions.php (and in other files). I have ...
0
votes
1answer
34 views

Hook into all password resets in Wordpress and get password before hashing?

I'm syncing my Wordpress authentication system with an secondary/external authentication system and my site has at least two ways of resetting the password, including: Password reset email User ...
-1
votes
1answer
23 views

how to handle multiple forloop?

I have and order_id as array but wc_get_order accepts only one id at a time how to loop through order_id and let the list of item id and item name? i am using this inside a class. it works fine if ...
0
votes
2answers
54 views

Control the srcset much more (not all sizes in it each time)

I'd like to be have more control on the srcset on certain important images of my website if not all. By default the srcset includes all the sizes created by wordpress for all the images. I'd like to ...
1
vote
1answer
67 views

Use wp_get_recent_posts with search term

I have a function that uses wp_get_recent_posts() I need to use this same function on my search page but am having problems adding the search parameter to the $args array. Does anyone know if this ...
0
votes
1answer
20 views

I want to change the Wordpress comments file

In the standard structure of Wordpress, a warning page appears when the user makes spam or goes too fast. The link structure of the warning page is "/wp-comments-post.php". Briefly (see images) https:/...