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
1answer
623 views

Getting out side of wp root folder from function.php using absolute path

Hi Everyone I am having a relative path issue with linking a css file using a absolute path. Basically I am having the exact same problem as the person here however I do not want to use the URL of ...
0
votes
0answers
7 views

How to modify or override a core function (wp_star_rating)

I'm looking for the way to modify a core function, in this case the wp_star_rating() function, declared in wp-admin/includes/template.php Actually what I want is to change the $title variable, cause I ...
0
votes
1answer
6 views

Add Featured image column into wordpress admin on pages AND posts

I have created a column in my functions.php file to add in a column to see the featured image on posts. However i would like to do this for pages as well, but if i repeat the code replacing posts with ...
0
votes
0answers
6 views

How to allow only auto indentation on TinyMCE

I want that Wordpress (or TinyMCE or any plugin) could auto indent my HTML (as switching from Text to Visual does), because I have lots of old posts that I need to edit and they are kind of minified. ...
2
votes
2answers
8k views

Get recent posts with thumbnail

I want to ger several recent posts. So I use wp_get_recent_posts. But I get only first image. <?php $args = array( 'numberposts' => '3' ); $recent_posts = wp_get_recent_posts($args); foreach( $...
1
vote
1answer
10 views

WordPress menu link doesn't work properly

I am developing custom site. The header links work on home-page but when I go inside shop then the home-link becomes siteurl/shop how to solve this? <div id="content" class="site-content"> &...
0
votes
1answer
671 views

Woocommerce - Removing Cart button for specific product category when product of another specific category is not in cart

I am trying to remove Add to cart button from products under "car_tickets" category when any product from "bus_tickets" category is not in cart. This is my code so far. add_action('...
0
votes
1answer
17 views

Wordpress upload_mimes not working for front-end uploads of 3D files

So, after the new WP updates my form will not allow certain files to upload. I have a Gravity form with an upload field to submit 3D print files. I can get one type of file to work, but not the others....
0
votes
1answer
699 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 ...
0
votes
1answer
28 views

How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?

My website is a daily deals and offers site. I promote many online stores with affiliate links. I have created a php script to detect any merchant's link (ex- Amazon) and convert it to my affiliate ...
0
votes
1answer
638 views

Display Year and Month from custom field + Age Calculator

I have a custom field "DOB" on my custom post type which is in [Ymd] format. I want to compare that date of birth to current time and want to show "You are # years # months." I am able to calculate ...
0
votes
0answers
12 views

Classic TinyMCE messing up only Contributor's HTML

I use a plugin that loads pre-defined HTML for my posts. I don't need the Visual editor, so I've disable it for everybody. Also, I want TinyMCE not to mess with my code. Nothing, no auto formatting ...
0
votes
2answers
716 views

How can I get the post id from within functions.php

I'm building a function within functions.php Within my function I want to make use of the post id of current post. How do I do this? The last thing I tried was this: global $post ; $id = $post->...
0
votes
0answers
23 views

Cleaner 'for each' loop for registering scripts in functions.php

I'm looking for a elegant way to register a ton of scripts I have sitting in a js directory on my server without having to sit and type them all out. I found this question here but it is 3 years ...
0
votes
1answer
8 views

Automated mark posts as featured every day

Hello Wordpress Community, I want to build myself a "recipe of the day" functionality. I'm looking for a way to mark 3 Custom Post Types per day as "Featured Posts" by a plugin or Cronjob. The ...
0
votes
1answer
614 views

Restrict user registration to emails on a single domain

I need to allow user registrations only for those with email addresses on a single domain. I have tested multiple regular expressions and this one works well in a regex sandbox environment, but as ...
7
votes
7answers
25k views

Remove type attribute from script and style tags added by WordPress

Warning: The type attribute is unnecessary for JavaScript resources. From line 10, column 146; to line 10, column 176 feed/" /> <script type="text/javascript">window Warning: The ...
0
votes
3answers
4k views

current_time('timestamp') seems to be different from the real current time

Does current_time('timestamp') have an issue? I am trying to get the current_time('timestamp'), and instead of giving me my current time: Jun 26 2013 14:30 It gives me: Jun 26 2013 21:30 I tried ...
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
629 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 ...
0
votes
1answer
644 views

Restricted images only for logged user. (hidden url)

Im looking for way to create page where only logged in user can see images, but images cant be index by browser, cant be accessed by not logged in user. Simply, if logged in user copy image link, ...
1
vote
2answers
87 views

Return only top-level navigation items from a menu using wp_get_nav_menu_items

I have the following function in my project: function cr_get_menu_items($menu_location) { $locations = get_nav_menu_locations(); $menu = get_term($locations[$menu_location], 'nav_menu'); ...
0
votes
0answers
15 views

Bifurcate woocommerce cart plugin in two parts

[woocommerce_cart] The above shortcode renders the woocommerce cart page, which will have these looks: What if we want just to generate just Part 1 or Part 2 as shown in the figure. Is that ...
0
votes
1answer
660 views

Redirect after login to current URL

I've my login box on any page of my WordPress and I'm trying to redirect to the same page after a user logs in. For example: If I make the login in the URL http://localhost/wordpress/category/sub-...
0
votes
0answers
7 views

Custom Customizer Image Sanitize fails to update image

I use this custom sanitizer to get the appropriate image size so that anyone using my themes can't mess up and put an 8k image in the website. The code works, but the problem I have is that once the ...
0
votes
0answers
6 views

Keep Page hierarchical order on Control Panel when I use 'remove_cap' 'edit_others_pages'

I'm admin user and just created several editor users who are 'NOT' allowed to edit other pages. Let me call them 'master editor','editor A' and 'editor B'. 'master editor' can edit top level parent ...
0
votes
1answer
16 views

Is it possible to use array_walk() to append terms to an array of posts?

I'm creating a masonry post grid of animals. I plan to filter the the visible posts by toggling classes. The classes would in turn would be the post's. I'm using an MVC theme and would like to get ...
0
votes
1answer
104 views

Dynamic Menu drops pages?

I've created a Dynamic Menu that highlights the selected page and colors for example the blog page "red" while the other links (home, about, contanct) remain white. My question is how can I make the ...
0
votes
1answer
14 views

Remove Font-Awesome MaxCDN Link & Load Locally

MaxCDN is slowing down my site so I want to load font-awesome locally but I can't seem to write the correct function to remove it. function remove_unwanted_css(){ wp_dequeue_style(‘font-awesome’, ‘...
0
votes
1answer
654 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 ...
0
votes
0answers
49 views

Load CSS file conditionally

Trying to load CSS file conditionally – only for specific pages with the following: add_filter('tablepress_use_default_css', 'tablepress_css_conditional_load'); function ...
0
votes
5answers
6k views

CSS stylesheet not loading

I'm brand new at theme development. My css stylesheet is not loading, and I'm not sure if the problem is in the functions.php, style.css, index.php, header.php, or footer.php file. I've added a div ...
0
votes
0answers
25 views

How to have multiple the_content() tags

I am designing a wordpress blog where you click on the title of the post and the content of the post opens up from the right side of the website. I was wondering if it was possible to have multiple ...
0
votes
1answer
18 views

Add HTML before a specific div?

I bought the "Woocommere Checkout Add-Ons" Plugin, which adds upsells to the checkout page - but it only allows to place text after the upsell checkbox. So I got the idea to add an image with some ...
0
votes
0answers
11 views

Webpage link got problem [closed]

When I'm using WordPress, i click on the product and it works, it direct to the product link page, but if i open as a user, the link are not working, it redirect to shop page instead of the product ...
0
votes
1answer
17 views

How best to check if a user is from China and hide content?

To speed up my website in China I thought of hiding blocked services from Chinese users and wrote this and put it in functions.php $isInChina = false; $ip = $_SERVER['REMOTE_ADDR']; // This will ...
0
votes
0answers
9 views

How to enqueue reactjs built theme to index.php to build wordpress theme

I am trying to make a wordpress theme using create-react-app package. But the problem is i have no idea how to put these files in wordpress directory to render it on index.php or how to enqueue these ...
0
votes
1answer
659 views

How to delete posts older than one year with post meta, post attachments and files?

Can anybody help me with a function to delete posts older than one year with postmeta, attachements and files? Tnx
0
votes
1answer
16 views

Override filter variable not working

I'm currently trying to override a filter in a plugin. This filter has 1 variable which defines a root path to a folder where some templates are located. This root path is normally in the assets ...
1
vote
1answer
45 views

Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?

I have been follow a tutorial here: https://rudrastyh.com/gutenberg/remove-default-blocks.html Where it discusses how to remove default Gutenberg blocks like so: add_filter( 'allowed_block_types', '...
0
votes
1answer
786 views

AJAX login without a plugin does not work. when add a action to function.php

I am using wordpress ajax login without a plugin. I want to not be allowed users access to the WordPress profile after login, Because i have designed a specific profile in the link: http://www....
0
votes
1answer
16 views

How to include any template using Shortcode fuction?

function custom_code(){ return include( get_stylesheet_directory() . '/custom-template.php'); } add_shortcode('custom_shortcode','custom_code'); As you can check above I want to include a ...
0
votes
1answer
12 views

Return category name with & Ampersand doesnt work

I have a category named: This & That However, for some strange reason my switch code doesn't pick it up. When I output $firstcat it does return This & That which makes it even more cumbersome....
0
votes
2answers
20 views

CSS change in woo commerce Place Order Text [closed]

add_filter( 'woocommerce_order_button_text', 'woo_custom_order_button_text' ); function woo_custom_order_button_text() { return __( 'Your new button text here', 'woocommerce' ); } Above is the ...
1
vote
2answers
952 views

Wordpress not cropping thumbnails properly

For some reason Wordpress is ignoring my thumbnail sizes and keeping thumbnails cropped proportionately instead of specific dimensions. Here is what I have in my functions.php: add_image_size('main-...
0
votes
1answer
804 views

Dynamically adding Captions to images

I have a site where the author has included Amazon Affiliate links. They've done this by adding the URL to product images. I'm wondering if there's a way to add a function that will automatically add ...
1
vote
1answer
959 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
2answers
2k views

Show the post date using the wp_get_archives() function?

I have some doubt about the wp_get_archives() function In my website I have create the following page template that use the wp_get_archives() function to show the posts list: <?php /** ...
55
votes
6answers
75k views

What's the difference between home_url() and site_url()

My understanding is that site_url() returns the location where the wordpress core files are. So, if my blog is hosted at http://example.com/blog then site_url() returns http://example.com/blog But ...
1
vote
1answer
2k views

how to edit functions.php in a child theme

I am using wordpress for my site. I am using a theme called esplanade. I have made a child theme folder and created a style.css with the required lines in it. My child theme is working nicely. I have ...