INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Best way to send users password? I used a plugin called WP Import to import a mass amount of users to my website. I now want to be able for them to log in using those accounts. How am I able to send them their passwords or get them to login to their account that we created for them?
You shouldn't have to send them passwords. That's a bad idea. Instead, make sure your web server has email setup properly and your user accounts have the correct email addresses. Then all you'll have to do is send them the link to the `Forgot Password` link provided by WordPress by default. It looks like this: ` Then from that page they'll be able to reset their passwords using their own email address. Alternatively, you may use a plugin like `Bulk Password Reset` or `Emergency Password Reset` to reset the passwords and send the password reset link to your users. Whichever method you follow, you must make sure your web server can send email to your users properly. Read more about WordPress password reset options.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 4, "tags": "users, password" }
How to implement ERP (Enterprise Resource Planning) into WordPress? How can I develop my ERP software in garments industry by using Wordpress? Is it best to use WordPress to use a ERP using WordPress. Have any readymade ERP in WordPress?
@Mark Kuplun is 100% correct. You can try We ERP. You need lot of customize if you fulfill requirements.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "api" }
How to get rid of index.php? Does anyone know how I can get rid of index.php in my URL? Right now if I add a new page, the address will be: www.mywebsite.com/index.php/page1 But I want it to be: wwww.mywebsite.com/page1 I surfed the web a lot! Changing the permalink doesn't work. Does anyone know how I can fix this?
This is a classical case. All you need to do is to use Rewrite Rules. With Apache, you can do it in .htaccess: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress More on this in codex.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "permalinks, site url" }
update_post_meta for repeated custom field I have a repeatable custom field made with "cmb2" plugin: $meta_box->add_field( array( 'name' => 'error', 'id' => '_pf_error_log', 'type' => 'text', 'repeatable' => true, ), ) ); How can i use `update_post_meta` (or any other function) to add a value to a new raw of that repeatable field (without losing the other raws)?
So the easiest way i found is: $field = get_post_meta( $propostid, '_pf_error_log', true ); $field[] = 'new raw string'; update_post_meta( $propostid, '_pf_error_log', $field ); But i will be happy to get a more simple and elegant solution...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom field, post meta" }
I want to change the author name I have a website where I am mostly posting translations. Therefore, I want to show name of the author of the original post instead of me on the author name area. How can I do this?
Here are three possible approaches: 1. A normal WP installation already has custom fields which you can add to your post. So you could use those to add the original author's name to. The only problem is that general themes usually do not display `the_meta`, because they do not know what to expect. In your case you would want to replace `the_author` in your theme with `the_meta` (don't mess with the original theme files, use a child theme!) 2. Easier, but a bit hacky: add the original authors to the user list. They don't need to know they have an account, just provide bogus e-mail addresses and don't let WP send their password to them. Now you can simply assign them as authors and they will have their own author page as well. 3. The most thorough approach is adding a meta box yourself (or use a plugin like WCK). This gives you complete control on how to insert the information in your child theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, custom field, author" }
how to change a theme slug I've opted to use the Understrap theme as a base theme for development. How do I safely change the theme slug throughout the theme files, i.e. everywhere `understrap` appears? Is it simply a case of performing a search and replace?
For a theme name `Hello World` a search and replace should be done in phases. 1. Make sure you do a case sensitive search and replace. 2. Replace `Hello World` with `Example Name` 3. Replace `hello-world` with `example-name` 4. Replace `hello_world` with `example_name` 5. Modify theme folder name 6. Look for any other namespaces that the theme uses and replace accordingly. These steps will ensure that there is no unintended replacement which may break the theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, themes, slug" }
Posts from a category on homepage with category archieves page default css I am trying to accomplish something. First am using two themes on my blog, on the mobile theme which is carrington, i would love to add five posts from a certain category or tag for example "Tech" to the footer of the theme or immediately after the recent posts. Update: what i think am trying to achieve is: category archieve pages and tag archieves has the same design (css) as the homepage. i just need to copy the design and contents of one category page archieve and place it in the footer section of my homepage. Any help please![The first section shows recent post then the other section \(IN THE NEWS\) shows post from a particular category with the design and css of the original post page. That is what am trying to achieve](
my mission was achieved by using some part of the code suggested above. I changed the xxxxx to my category slug then below that code i posted all of my loop and that was it. So if you want it to have your post page design: 1. copy this 2. copy the whole of your loop and paste under and save
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, query posts, homepage" }
Is there a hook to Intercept al urls from a webpage and redirect to a page After a long search through all actions and filters. I was unable to find a url intercepting hook. To put in the function.php in my plugin. Is there a way to catch all urls that go to my webpage, and has this kind of directory: www.webpage.com/product/number-and-name-product. Intercept thist url and lead to a wordpress page. more info: I have made a plug-in to make a catalog to show all products with a shortcode on a wordpress page. now i only need to click the product and go to a detail page with the old url here is where i get confused. if i make a second page in wordpress i dont get the url right. thanks in advance
If you're not comfortable editing/don't have access to your .htaccess file, a plugin called "Redirection" should serve your purpose: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, filters, urls, actions" }
Exclude all tagged posts from WP_Query loop Does anyone know how to exclude all tagged posts from WP_Query loop? I can do it with **'tag__not_in'** for specific tag IDs – see below: <?php $loop = new WP_Query( array( 'post_type' => 'poetry', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'ASC', 'tag__not_in' => array(8, 9) ) ); ?> But I was wanting to eliminate all tagged posts without updating the tag IDs in the **'tag__not_in'**. Cheers, Damian
Use the tax_query parameter with the taxonomy set as post_tag. See the following previous answer: Get all posts without tags
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, tags" }
Split site title and apply different classes I'm currently designing a theme using Underscores and I want to do something like this with the site's title: Thisisthe **title** So the title is all one word and the last five characters are different to the rest. I am currently using the bloginfo function to display the title and I can't figure out a way to split it so I can style each section of the title differently. I have tried creating a function to splice it, but to no avail.
Figured it out! function split_title($title) { $title = get_bloginfo('name'); $word = substr($title, 0 , 5); $press = substr($title, 5); $html = "{$word}<span class='bold'>{$press}</span>"; return $html; } And then `<?php echo split_title($title); ?>`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, css, title, bloginfo" }
Count number of posts by author in a category What is the optimal method for getting the number of posts by an author in a category? I'm not looking to get the posts themselves, just a count of them. count_user_posts returns a count of all the posts of a user in a post type, but there is no option to filter by category. Any ideas would be much appreciated. Thanks!
You could do this by creating a custom `WP_Query` and then counting it. $args = array( 'author' => 1, 'cat' => 5, ); $my_query = new WP_Query( $args ); $my_count = $my_query->post_count; Just change `1` and `5` to the Author ID and Category ID respectively. Alternatively you can use the category slug or author's **nice name** (NOT name!) as well: $args = array( 'author_name' => 'bob', 'category_name' => 'editorial', };
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "count" }
Finding where a shortcode comes from I have to change a few things in a page that I have not created. I have to insert some text inside a contact form. When I go to edit that page all I see is some shortcode. It's a custom shortcode that looks like [companyName_apply_form]. I have no idea where it comes from. It's not coming from the contact form plugin that created the other contact forms in the page and I also can't find anything in the template files. Any idea where a custom shortcode like that may come from?
Just use the Windows search bar in `wp-content` directory and search for `companyName_apply_form`. You should find the file where the shortcode is created. To add a shortcode in Wordpress you normally use this syntax: 'add_shortcode("shortcode_name", "function_name")'
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "shortcode" }
Version control for both Vagrant config and themes being developed I have set up a local Wordpress development environment using Chassis (based on Vagrant), this needed a bit of tweaking to get it how I like, so I feel like I should have this under version control. There will be changes in future. I will be using this Wordpress install for theme development, ideally I would like to develop in the "themes" folder, but would it cause problems having a Git repo within another Git repo? Is there a way to manage this, keeping both the environment and theme under verison control?
I also asked this question on SO and the answer was to use .gitignore for the subfolders containing the themes I am developing. This has worked well for me.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "theme development, themes, customization, git, vagrant" }
If Home Page Do Nothing, If All Else Show This Content I have this code: <?php if (is_single() || is_page() || is_archive() || is_404() || is_tag()) { ?> <div class="single-page-title"> <div class="spt-wrap grid-container container grid-parent"> <div class="spt-title"> <h1><?php the_title(); ?></h1> </div> </div> </div> <?php } elseif (is_home() || is_front_page()) { ?><?php } ?> I would like it to only show the HTML content on all other pages/posts/archives other than the home page itself. I do not want it to show on the homepage. Can someone rewrite this for me? Thank you kindly
It sounds like you're looking for: if ( ! is_home() && ! is_front_page() ) { // the stuff you don't want to show on the front/home page } where we use that `! ( A || B ) = ! A && ! B`. But it also depends where in the theme you are using the code snippet.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "options" }
Someone created a child theme, but I need to modify it to reorder content. How do I access the child theme? I'm fairly new at wordpress but I am currently trying to figure out how to access someone's child theme that they created from a parent theme. I can access the editor section but it just gives me the php. Is it possible to access the HTML? I'm wondering if someone can explain how come there isn't like an index then a post page. I just need to reorganize the content since the layout orientation isn't correct.
You are looking at the right files area. The HTML is created through the php files. These files can be accessed/edited through the editor as you are viewing or through FPT as Laxmana suggested. Through ftp it would be in your public_html/wp-content/themes/your-child-theme folder. It may not only be the index.php file that you're looking to change though, or you may need to change something other file entirely. It's better to make the changes via ftp because you can back up your files before you start making changes in case something goes wrong. If you don't have that option the editor works as well. Just select all the content for the file you are editing and copy it to your desktop (word or notepad etc) so you have a safe recovery point. Without knowing exactly what you are tying to change this answers your question as best as possible.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "child theme, html" }
Why is my RSS feed not working? I have the following blog on a WordPress site. The RSS feed does not contain a list of the posts. Any thoughts on what is going on? **UPDATE** I noticed that my blog index page was located at < whereas the blog posts path began with < (notice the missing "-blog"). I changed the blog index page to < but it did not fix the feed.
Your feed is there. You can check this by opening the source code of your homepage and find these lines: <link rel="alternate" type="application/rss+xml" title="Talent Hero Media &raquo; Feed" href=" /> <link rel="alternate" type="application/rss+xml" title="Talent Hero Media &raquo; Comments Feed" href=" /> If you click on the first link you will be led to the source code of the actual location and presto ... there's your feed. Unfortunately, when you run the url `.../feed/` you are rerouted to the comments feed. Actually `.../comments/feed/` sends your to `.../feed/` as well. If you look in the source code of the comments feed you see: <atom:link href=" rel="self" type="application/rss+xml" /> So, for some reason (presumably a plugin) your comments feed url is overwriting the post feed url. Disable all plugins and switch them on one by one to find the offender.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, rss, feed" }
What image is this pulling? I inherited a site with a custom php file for a custom sidebar. The sidebar is pulled in to action on pages using the "About" template. The sidebar is supposed to be displaying the image of the person whose profile it is on the top of the sidebar. Only one of the 4 profiles is pulling the correct image (the other 3 are trying to pull images from an old dev site that no longer exists). So, I need to update the 3 pages to pull images from the current site. But, I can't for the life of me figure out where to do that because I can't figure out where the photo is being pulled from. The profile pages are just regular pages whose parent is the "meet the team" page and they are using the About Page template. The code in question is this: `<img src="<?php $image = get_post_meta(get_the_ID(),'image',true); $profile = get_post_meta(get_the_ID(),'profile',true); print $image; ?>" />` Any help or insight into what photo this is pulling would be greatly appreciated.
`$image = get_post_meta(get_the_ID(),'image',true);` This line is pulling the URL of the image from a custom field for that particular profile page. Do you see any custom fields in the admin there? Make sure you have the `custom fields` checkbox checked in the `screen options` tab (top right in the page admin).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, customization, sidebar" }
Change the template of multiple multisite pages at the same time I have a multisite network with hundreds of individual location-based sites that use the same theme and display the same type of content. Occasionally I will need to create or change the template of a page for one site and do so by logging in and out of each subsite to repeat this change across the network. Is there a better way to do this through the shared theme? Ideally, I would like to learn how to define a set of rules: if page name is equal to "Example", always use the `example.php` template file and so on.
If these pages are using the default `page.php` template, just create a file called `page-{slug}.php`. So for example, if each subsite has a page with a slug of 'my-cool-page' you'll create a template file called `page-my-cool-page.php`, upload it to the active theme, and all of the pages with that slug will automatically use that template. (If it's not a custom-coded theme, be sure to use a child theme so your changes won't be lost.) If the pages are already using a custom template - i.e. you selected `tpl-my-cool-template.php` from the template dropdown in the editor - that will override `page-my-cool-page.php' and you will have to update them one by one. But it does not sound like that is the case.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, multisite, templates" }
Using a javascript file to access a get posts array I would like to use arrows to dynamically change which posts appear in a div by cycling through an array of say 5 posts. How would i approach this issue? I have made the array that the get posts function is assigned to a global variable, but that's the only thing i have done so far, as I am kind of stumped. I tried using the debug log to print the array to get some sense of how to use it, but it doesn't make any sense at all. Would this have something to do with wp_localize_script()? Also I'm looking to have three of these on my front page so, if I use wp_localize_script() can i use this three times? To pass three separate arrays of posts?
Yep, you're looking for `wp_localize_script()`. Do away with the global. add_action( 'wp_enqueue_scripts', 'wpse_enqueue_scripts' ); function wpse_enqueue_scripts() { wp_enqueue_script( 'wpse-main', get_template_directory_uri() . '/path/to/script.js', array(), false, true ); wp_localize_script( 'wpse-main', 'wpseVars', array( 'postsLoop1' => json_encode( /* first post array */ ), 'postsLoop2' => json_encode( /* second post array */ ), 'postsLoop3' => json_encode( /* third post array */ ) ) ); } Then in your script, you can access the variables by grabbing `wpseVars.postsLoop1`, `wpseVars.postsLoop2`, etc.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "php, posts, javascript, array" }
Enable/Disable WP options programmatically o/ SO So I'm working on a plugin, that i use together with all my themes, where i have added a little option page. From my option page i would like to be able to disable stuff like WP_DEBUG, DISALLOW_FILE_EDIT and so on. But I'm not quite sure if its even possible to do so? i have been searching for some time now, and i seem unable to find actually information whether this is possible (and how if it is)
I understand what you are trying, to make changing the WP config settings more convenient but I do not think it is possible to change them from a plugin. Constants like WP_DEBUG and DISALLOW_FILE_EDIT are defined in core files, specifically in `wp-config.php`, according to the Codex and, looking over the source code of this file and related files, I could not find any hooks to affect their definition. And, in PHP, once constants are set they can no longer be changed during execution. Their value cannot be changed and they cannot be unset. Attempting to redefine or unset a constant will result in an error. Here is a small quote from the PHP manual on constants: > As the name suggests, that value cannot change during the execution of the script If there are no hooks to affect the definition of these constants and if they cannot be unset, then I do not see a way around this. Editing the `wp-config.php` file seems to be the only way to change the settings.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, debug, options" }
Error: The uploaded file exceeds the upload_max_filesize directive in php.ini I am getting error while upload 5mb video file in wordpress media section. How can I solve this issue?
You need to make changes in the PHP configuration file (php.ini). For example, if you are working on a local server and using XAMPP, you can access this file in two ways: * Open the XAMPP application and go to Apache > Config > PHP (php.ini) * Or open the XAMPP installation folder, usually at C:\xampp, and you can find the file at php\php.ini. Once you open the file, search for `upload_max_filesize` and increase the limit value to something that you prefer, like `80M` (that will be a maximum size of 80Mb). If you are using a local server on a Mac, there will be a similar process of finding the php.ini file of your PHP installation and changing the limit in the same way. This error usually occurs for local PHP installations and that is why I referred to them here. If you have this error on an online server, then again, you need to find a way to edit the php.ini file of your server.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "uploads, media" }
How to add a custom id to each post URL in wordpress I'm working on wordpress site. I use custom post type as my post type. I want to add custom id with character to post url like `www.mydomain.com/g123/postname/`. And i also need if i delete `/postname/` part from url it must be redirect to the post `www.mydomain.com/g123/postname/`.
i wasn't able to add custom id but i show the post id in url with a character like this `www.mydomain.com/%category%/g%post_id%/%postname%/`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "php" }
How to remove the post pagination (Next page tag) depending on type of traffic source: from utm_campain or non-utm_campain Let me try to explain my problem. I want to create the next traffic filter: if user comes from utm_camnpain source the post will be show with pagination, if from other source the post will be show in single page. I tried code from here and put it exactly after`<?php`tag in single.php (Single post). Maybe, somebody can help me.
So, I found the decision: add_action( 'the_post', 'campaign_remove_nextpage', 99); function campaign_remove_nextpage ( $post ) { if (($_GET['utm_campaign']== 'Facebook' || $_GET['utm_campaign']== 'Twitter') && (false !== strpos( $post->post_content, '<!--nextpage-->' )) ) { } else { $totalArticlesPages = substr_count($post->post_content, '<!--nextpage-->'); // Google: not paginated // Direct: not paginated // Camp: paginated // Reset the global $pages: $GLOBALS['pages'] = [ $post->post_content ]; // Reset the global $numpages: $GLOBALS['numpages'] = 0; // Enable multipage $GLOBALS['multipage'] = false; }};
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "filters, pagination" }
How can i hide the authors box from a specific set of categories and post types? I want to just hide the authors box under the posts for few specific categories, while on the rest it will remain visible as is.
This depends on your theme. If it has no option for this, you'll have to do this yourself. Find the template where the author box is generated (presumably `single.php`) and copy it to a child theme. Then make the production of the box conditional to the current category; if (!is_category (array ('exclude-this-category, another-category-to-exclude')) { echo '<div class="post-author-bio" itemprop="description">'; .... echo '<div>'; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "categories, theme development, css, author" }
How to delete unused URL? If I modify the URL of a post, that URL is still being used by the post. If I try to create a new post and use the hidden URL, I'll get an error. Is there some way to find all of these hidden, unused URLs and delete them?
Whenever you change the slug of a permalink **on posts** ( and custom post types with post capabilities ), WordPress will save the old slug in the post_meta table with the key `_wp_old_slug`. On a normal installation the old slug should redirect to the new slug using `wp_old_slug_redirect()`. There are a couple ways to remove them, the easiest is probably SQL directly: /** * Delete posts old slugs from database in WordPress */ function delete_old_slugs() { global $wpdb; $wpdb->get_results( "DELETE FROM wp_postmeta WHERE meta_key = '_wp_old_slug'" ); } delete_old_slugs(); You may also be able to find a plugin to do the work for you, the first one that I could find is Remove Old Slugs plugin which will also supply you a list of the old slugs which seems neat.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "urls" }
plugin_action_links_{$plugin_file} hook not in the main plugin file I'm developing a plugin and I've organized its code in separate files. The admin functions file is inside an `/admin` subfolder. In this file I enqueue scripts and styles, add meta boxes and so on. I'd like to add some action links to the installed plugins screen using the `plugin_action_links_{$plugin_file}` hook, but I cannot get it to work. As this hook is added outside the main plugin file this doesn't work: add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_action_links' ) ); My question is, how can I get the `plugin_basename()` of the main plugin file from a different file in a subfolder? Is it possible? Thanks in advance
You can simply store the basename in a variable in the main file and reference that variable in the admin file. If you are using classes, which I determine from your example code, you can simply create a static property in you main class and reference that in the admin class: class My_Plugin { static $basename = null; public function __construct { $this->basename = plugin_basename(__FILE__); } } class My_Plugin_Admin { public function change_action_links() { add_filter( 'plugin_action_links_' . My_Plugin::$basename, array( $this, 'add_action_links' ) ); } }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, filters, hooks" }
Unique 4 digit number I need a feature on my site that can either generate a unique 4 digit number, or a field where you can choose your own 4 digit number. It is very important that no one can have the same number. Also i need to store the numbers that have been generated. Any idea how i could build something like this? Any plugins? I have used WPForms plugin to store data from filled forms, but it does not have a "unique" field feature.
For unique 4 digit number, the following code work fine function unique_number($length=10) { $string = ''; // You can define your own characters here. $characters = "0123456789"; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters)-1)]; } return $string; } print unique_number(4); Every plugin has extended capability to change the default value of field or form. You should need to know how this work. I am giving you the example for ACF custom fields. //for acf function my_acf_load_field( $field ) { $rand = unique_number(4); $field['default_value'] = $rand; return $field; } add_filter('acf/load_field/name=your_field_name', 'my_acf_load_field');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins" }
How to remove auto generated markup? I'm using a plugin which adds a review box to the post content. There's a problem with the layout of the review box due to auto generated `<p>` and `<br>` tags being added to the markup. I tried a few plugins including this one: < but they didn't help.
In the template file where it's rendering you can use PHP's strip_tags function <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "html" }
Help with is_page() and calling css for specific pages in a Child Theme I'm building a child theme of Newspaper 7, and I'm trying to call a specific stylesheet for certain pages, however is_page() isn't working for me. What should I change in my code to be able to do what I'm trying to do? Here is my code: <?php add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 1001); function theme_enqueue_styles() { wp_enqueue_style('td-theme', get_template_directory_uri() . '/style.css', '', TD_THEME_VERSION . 'c' , 'all' ); wp_enqueue_style('td-theme-child', get_stylesheet_directory_uri() . '/style.css', array('td-theme'), TD_THEME_VERSION . 'c', 'all' ); if( is_page( array( 'about-me', 'contact', 'social-media'))) { wp_enqueue_style( 'td-theme-child', get_stylesheet_directory_uri().'/style2.css'. 'c', 'all' ); } }
The first parameter of `wp_enqueue_style` and `wp_register_style` is used to register the stylesheet for later use. So, you can register it early and later call it just specifying it's first parameter. In this case you are registering and enqueueing the stylesheet `td-theme-child`, which file is `style.css`. After that, if the conditional passes, you are registering and enqueueing the stylesheet `td-theme-child`, which file is `style2.css`... but, WP already sent the `td-theme-child`, so the `style2.css` will never hit the browser. So, in short, just change the first parameter of your style2.css enqueue line: wp_enqueue_style( 'td-theme-child2', get_stylesheet_directory_uri().'/style2.css'. 'c', 'all' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, css, child theme" }
Recovering the table wp_usermeta from users We had an accident and the table wp_usermeta got truncated. I have the table wp_usermeta from the staging environment I pushed it in but when I try to login with the admin user (id 1 on both of them) I'm getting this message: > Sorry, you are not allowed to access this page. I'm being able to login but that's shown on the wp-admin home page Thanks a lot for any ideas
Try it: INSERT INTO `wp_usermeta` VALUES (NULL, '1', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}'); INSERT INTO `wp_usermeta` VALUES (NULL, '1', 'wp_user_level', '10');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "database, users, login, user meta" }
Hiding the widget meta box in the Appearance->Widget screen I don't want to unregister_widget() the widget on the screen, rather, just hide them for admins. Any ideas? I tried: remove_meta_box('widget-id', 'widgets'); but I couldn't figure out the second argument - the screen/page that the widget is displaying on because I can't find the id of the widgets screen <
This should already be the case, non-administrators do not have access to the 'Appearance' menu by default. Here is a list of each role and their capabilities: < * * * Okay so if you want to hide it for everyone, remove_meta_box() won't work because it's not a meta box as far as I can tell from looking at the source. So alternatively what you could do is: 1. Remove the menu item using `remove_submenu_page('themes.php','widgets.php');` however the page would still be accessible to admins if they just type in the correct url. 2. Use css to hide the widget. Use `admin_enqueue_scripts` to set that up.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "widgets, metabox, admin menu" }
Image with large file size not cropping I just set hard crop in function 676x429 hard crop. add_image_size('home-slide', 676, 429, true); Its working but client uploaded a large file something like 3800x3800 (5.73mb) and it doesn't crop. But when I reduce the size by 1600x1600 and it works. Why it doesn't cropping on large files?
By default, WordPress uses the GD Graphics Library to resize and crop images. On servers with limited resources however, GD fails on images with large file sizes. If you really need to keep the size of your images, but want to keep your file sizes down, consider processing your images first with tinypng.com. Their online compressor retains as much quality as possible, processes up to 20 files at a time, and is free.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post thumbnails, images, cropping" }
can anyone help me converting my static menu to wp_nav_menu I'am trying to add static menu item to Wordpress Menu <nav> <ul class="navigation" > <li class="normal" > <a href=""> <span class="label-nav"> </span> <span class="label-nav-sub" data-hover=""> </span> </a> <ul> <li> <a href=""> </a> </li> <li> <a href=""> about us </a> </li> <li> <a href=""> location </a> </li> <li> <a href=""> contact </a> </li> </ul> I have tried this code but it doesn't work I'm new in WordPress
<?php wp_nav_menu(array( 'theme_location' => 'menu_location', 'container' => false, 'items_wrap' => '%3$s', 'items_wrap' => '<ul id="nav-primary" class="navigation %2$s"><li class="normal"><a href=""><span class="label-nav"></span><spanvclass="label-nav-sub" data-hover=""></span></a> %3$s</ul>', )); ?> Above example you can use your static item as well. TO make it dynamic you can use nav walker see this example - <
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "menus" }
Theme customizer hiding sections I have customizer sections and fields setup which work fine if I don't include `wp_footer()` in my theme. Can someone shed some light on what's forcing the section and hides to be set to `hidden` the customizer section? I have included a GIF of the sections hiding below. ![]( (the page takes a few seconds to load and then once the page is loaded, the sections hide) As I said, if I remove `wp_footer()` from my theme, they work fine. The data is being saved and loaded up in the template and all the fields appear on every page as part of the theme's global sidebar and footer.
add_filter( 'customizer_widgets_section_args', function ( $args ) { $args['active_callback'] = '__return_true'; return $args; } ); Adding this to my `functions.php` file ensured that the settings stayed visible no matter what page was visible.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "themes, theme customizer" }
WPDB Join with custom table I am trying to query info from a custom table created by a calendar feed. The calendar feed created a post with the title for each event, but the event data is in a different table instead of post_meta. Here is what I am trying with no results: $sql = "SELECT post_id". "FROM {$wpdb->prefix}calp_events". "JOIN {$wpdb->prefix}posts ON (ID = post_id)"; $results = $wpdb->get_results( $sql ); The id of each calp_events is the same as the post ID. I want to be able to echo results from both tables after my query.
I think you need to distinguish which table your ID and post_id come from. Take a look below and notice how the tables get a variable assigned. You could also just use the table name, but this reads easier. SELECT P.post_id FROM [prefix]_calp_events as EV JOIN [prefix]_posts as P ON EV.ID = P.post_id You stated that you want to read the results from both tables. The join actually returns only matching records in both tables. Check out < for details on how joins work.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wpdb" }
Can i put my shortcode inside a variable in php files? for example something like that <?php $check_in = [st_custom_meta key="st_custom_available_dates"] ; ?> i do not know if i use this the right way or if this is even possible.. Any thoughts? Thank you in advance
You need to call do_shortcode(), as in: $check_in = do_shortcode ('[st_custom_meta key="st_custom_available_dates"]') ;
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php, functions" }
Custom JQuery script in page template won't work i created custom page template where i inserted followed JQuery script. <script type="text/javascript"> $( document ).ready(function() { console.log( "ready!" ); }); </script> But it wont work. I get Object expected error. Jquery is inserted on page header so it should be loaded. Why is that not working?
The version of jQuery distributed with WP runs in noConflict() mode (meaning that `$` is **not** bound to the jQuery object). Thus, you should do: <script type="text/javascript"> jQuery( document ).ready(function() { console.log( "ready!" ); }); </script> or <script type="text/javascript"> (function ($) { $( document ).ready(function() { console.log( "ready!" ); }); })(jQuery) ; </script>
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "jquery" }
Read more link to external webpage is it possible for the "Read More" buttons in front page which normally leads to the post , to change it to lead to an external webpage. So one can lead to post and the other can lead to external webpage
Yes, you can use the Read More filter: < Per the discussion below, in this case, there's a plugin called Page Links To that may solve your problem. You would create a post in WP but set its permalink to the external URL you want to link to, so it would appear on the front page but its read more button would go to the external URL for just that post (or however many others you created this way).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "links, read more" }
Add div before the first paragraph the_content I need to add a div before the first paragraph. Example: <div class="ads-site">ADS </div> <p>First Paragraph</p> <p>Second Paragraph</p> My Function: global $post; function my_content_div( $content ) { $content = '<div>My div</div>' . $content; return $content; } add_filter('the_content', 'my_content_div');
Yogenisia's is right that you should use `the_content` filter. If you want to insert something before the first paragraph, locate the first `<p>` in `$content`, then insert your `div` with `substr_replace`. add_filter( 'the_content', 'namespace_insert_before_first_paragraph' ); function namespace_insert_before_first_paragraph( $content ) { $my_div = '<div> ... </div>'; $first_para_pos = strpos( $content, '<p' ); $new_content = substr_replace( $content, $my_div, $first_para_pos, 0 ); return $new_content; } Keep in mind however that many embeds, such as Twitter's, wrap their content in a `<p>...</p>`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, the content" }
Add two input fields in add_settings_field I want to add a third column consisting of an input textfield using the Settings API. Is this possible? function print_custom_field() { $value = get_option( 'my_first_field', '' ); $value_second = get_option( 'my_second_field', '' ); echo '<input type="text" id="my_first_field" name="my_first_field" value="' . $value . '" />'; echo '<input type="text" id="my_second_field" name="my_second_field" value="' . $value_second . '" />'; } add_filter('admin_init', 'register_fields'); EDIT: I tried this code and Wordpress doesn't save the values of the second input field. Only the value of the first input field gets saved. How can I show another text input in the same row?
All I needed to do was `register_setting` for the second input.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "settings api" }
How to hide some users to unlogged users I have a WordPress site with the Tiger Theme. It's a kind of social site, and there are two types of users: 'Professionals' and 'Corporates'. I would like to hide the 'Corporates' from visitors (with or without an account) that are not logged in. I would like that the corporates profiles are visible only for registered users with approved subscription (Status: ACTIVE). Is there a way or plugin to do this? Thanks!
You haven't posted any code so I won't be able to precisely post an answer for you, but this it what you can do. Find the page that is rendering the profiles, open it and add this piece of code in it: <?php $user_info = get_userdata($id); $role = $user_info->roles; if ($role =='corporates' && !is_user_logged_in()) { wp_safe_redirect( site_url()); exit; } ?> Which `$id` is the user id of the profile owner, not the visitor. If you add more technical information about your problem I will update the answer for you.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "users, user roles, user registration" }
What is the best way to save and retrieve Multiple rows of data with the Settings API? I'm a beginner plugin developer. I need my plugin to save and edit multiple indexed sets of key/value pairs on my custom settings page and retrieve later them by their index on the Appearance>>Widgets page. Is it best to create a custom table in the database for this or does the Settings API have dimensional accommodation for this? If so can someone please get me pointed in the right direction? TIA
Because you mentioned the Settings API I assume you want to do AJAX from the admin area of wordpress. You have some research to do, so my answer is to check out these: < < That should get you where you need to go. Happy Wordpressing!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "settings api" }
Unable to point the child theme directory even using get_stylesheet_directory() I am developing a child theme based on **storefront** as parent theme. I am trying to include files in child theme `functions.php` file as: require_once get_stylesheet_directory() . '/inc/_customizer.php'; require_once get_stylesheet_directory() . '/inc/_header.php'; When I move any function from `functions.php` file to `_header.php` or `_cuztomizer.php` files which are in the `inc` folder in the child theme it does't works but either in `functions.php` file it works very well. I don't know what I am doing wrong and how I can include files in `function.php` file. Please help me. Thank you in advance
The answers to this question state that `require_once` operates at a file-system level. I would try `include get_stylesheet_directory() . '/inc/_customizer.php';` try to change `require_once` with `include` and see if that works. If it does, you can research how to use `require_once` correctly at your leisure.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, child theme, include" }
Disable email field on WooCommerce customer account details Is there a possibility to disable the email field on WooCommerce customer account details? Or Is there a hook or action available to do such thing? I'm just using a pre-made themes and not that much into PHP. Have tried this plugin called "Prevent Email Change" by Happy Plugins, but it didn't worked. Would really appreciate any help from this. Thanks,
You can do it by adding this code to `functions.php`: function custom_override_checkout_fields( $fields ) { unset($fields['billing']['billing_email']); return $fields; } add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 1000, 1 ); But it is wrong approach, since WooCommerce uses email to notify user about status of the order.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "customization, hooks, woocommerce offtopic, actions" }
Why does Featured Images not load in the backed? Here's my code in the functions.php file: <?php // Excerpt Length Control function set_excerpt_length(){ return 85; } // Theme stream_support function wpb_theme_setup(){ add_theme_support( 'post-thumbnails' ); } add_filter('excerpt_length', 'set_excerpt_length'); Any idea what I am doing wrong here? Thanks! ALSO! I notice that the functions.php never has a closing ?> - how come?
In your code excerpt you have a function to add theme support for post thumbnails but you don't include a line where you actually run it. Can you confirm that you are also executing wpb_theme_setup() as well as defining it? If it's the only thing in the function, you could just call `add_theme_support( 'post-thumbnails' );` on its own (that is, remove the wrapping function). The closing ?> is not compulsory in PHP
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions" }
Style wp_page_menu() items I'm new to developing a custom template in Wordpress but I fail to see how I can style a menu item seperately. With `posts` I can loop through them and place them in custom html elements. With `wp_page_menu()` I can only output the whole list. How can I loop through each item and place them in my custom template? **Html Template:** <ul class="nav navbar-nav navbar-right is-hidden"> <li> <a class="page-link" href=""> ... </a> </li> ... ... </ul>
Please find below the function for showing navigation menu. Here, `$menu` is equivalent to **_Menu name, ID, or slug_** <?php function showMyMenu($menu) { $navData = wp_get_nav_menu_items($menu); ?> <ul class="nav navbar-nav navbar-right is-hidden"> <?php foreach($navData as $k => $v) { echo '<li><a class="page-link" href="' . $v->url . '"> ' . $v->title . ' </a></li>'; } ?> </ul> <?php } ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, menus, navigation" }
XML asset fails to load using https The wp-admin are of my site is available via https only; for that reason any use of `get_template_directory_uri();` in the admin area generates a url as such < I am able to successfully enqueue scripts and styles using `get_template_directory_uri();` however when I attempt to use `simplexml_file_load();` to access a local xml document in the admin area of the site, the file fails to load. I can get around this by hardcoding a non https version of my theme directory, but for obvious reasons, this isn't practical. **Summary:** `simplexml_load_file(get_template_directory_uri().'/myxml.xml');` \- does not work `simplexml_load_file(' \- does not work `simplexml_load_file(' \- does work
In case this helps anyone in the future: The problem was not a WordPress issue, it was a server configuration issue. Useful explanation on checking which stream wrappers are enabled on your server (used this to make sure https was enabled on my server) Enable Stream Wrappers Someone with the same issue found that their certificate failed to verify: Certificate Verification Fails The issue was fixed by our hosting provider, with the following explanation: > The problem is caused by the the self signed certificate on the server. We could either allow the self signed certificate in the php setup or load a valid SSL certificate. > > The issue was fixed by creating a self signed certificate which matches the Openssl common name. This fixed all libxml errors
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "ssl, xml" }
Pass multiple PHP variables to JS in Options Page I'm passing variables from options to the front-end using `wp_localize_script`. Issue is that now I have 71 input fields in the options page with these ids: `calc_m_transport_1`, `calc_m_transport_2` and so on till 71. What would be the efficient way to pass this data to the front-end? Right now this is how I'm doing it: $phpValues = array( 'value1' => get_option( 'plugin_name_value1'), ); wp_localize_script( $this->plugin_name, 'phpValues', $phpValues )
I think you are looking like : $phpValues = array(); for($i=1;$i<=71;$i++){ $phpValues['value'.$i] = get_option('plugin_name_value'.$i); } wp_localize_script( $this->plugin_name, 'phpValues', $phpValues )
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "wp localize script" }
Order tags by the order they were typed I would like to know if it is possible to make the tags of posts to appear by the order they were typed. If it is possible, I would really appreciated to show me the details. Many Thanks. Mario
To display post tags in order they were entered into WordPress, use this within the loop (returns a list of tag links): echo '<ul>'; $tag_list = wp_get_post_terms(get_the_ID(), 'post_tag', array('orderby' => 'term_id', 'fields' => 'all')); foreach($tag_list as $tag) { echo '<li><a href="' . get_term_link( $tag ) . '">' . esc_html( $tag->name ) . '</a></li>'; } echo '</ul>';
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "tags, order" }
Why am I unable to login to Dashboard after adding myself to admin via phpMyAdmin? So I have added myself as an admin via following the instructions on this site: < I have done this before and it has worked. When I go into the dashboard and add the creds as I inputted them via phpMyAdmin according to the steps in the URL above, I get an error message saying the username and/or password is incorrect. When I try to email myself a password reset, it says the email address is not recognized. I go back into phpMyAdmin and all the info is there under wp_users and wp_usermeta. What could be going wrong?
For several years already, WordPress does not use md5 to encrypt passwords. Instead, Portable PHP password hashing framework is used. That is why described method doesn't work anymore.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "phpmyadmin" }
Delete duplicated wp_postmeta record I have many duplicated wp_postmeta record (about hundreds record with same post_id & meta_key) and need to delete safely via mysql, is there any effective way to delete the postmeta record. ![wp_postmeta table]( Further question is how to create code implementation to prevent this postmeta duplication. Many Thanks :-)
It is quite complicates grouped request, so to avoid problems, consider to use Cleanup Duplicate Meta plugin. The reason why duplicate entries are occured is usage of `add_post_meta()`. Just use `update_post_meta()` (even to create meta, it works) - and you will have always one meta field with certain name per post.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "posts, post meta" }
wpdb get results doesn't work with variable this is my code: $search_by_input= $_POST["search_by_input"]; $client_id_by_nick_name = $wpdb->get_results('SELECT user_id FROM '. $user_meta_table .' WHERE meta_value ='.$search_by_input, ARRAY_A); it doesn't work. but when I write the value instead of variable it works: $client_id_by_nick_name = $wpdb->get_results('SELECT user_id FROM '. $user_meta_table .' WHERE meta_value ="admin"', ARRAY_A); when I use `var_dump` for `$search_by_input` it shows this: string 'admin' (length=5) The only difference between that two lines is double quotation(before and after `admin` in second code.). So Please tell me how can I fix this problem. Thanks
Try it: $search_by_input= $_POST["search_by_input"]; $client_id_by_nick_name = $wpdb->get_results( sprintf( "SELECT user_id FROM `%s` WHERE meta_value = '%s';", $user_meta_table, $search_by_input ), ARRAY_A);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "wp query" }
Need logged in users returing to site redirected to a separate page Users to the site can register and log in and access a special page `members.php`, which is the home page of their account. But if they leave the site and come back (provided they are still logged in) they need to be landing on `members.php` and not my regular home page. Now everyone, logged in as well as logged out, folks land on the `index.php` page of my site. How to make the above possible?
Add this piece of code to your theme's `functions.php` file: <?php if (is_user_logged_in() && !is_page('YOUR PAGE SLUG') && empty($_SERVER['HTTP_REFERER'])) { wp_safe_redirect( site_url('/members.php')); exit; } ?> Assuming that your `members.php` is located at ` This will redirect any logged in users to that page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "customization, redirect" }
Display a list of child posts on parent posts of a custom post type I have a hierarchical custom post type called 'products'and I have created a 2 level parent-child relationship. I want to list all the subpages/child posts on each parent post but I have tried everything and nothing works. I tried the page-list plugin and it only works for the default 'Page' post type. Same with the tutorial found on wpbeinner.com titled "How to Display a List of Child Pages For a Parent Page in WordPress". Both work for default page type but not the custom post types. Would appreciate some input. Thanks
The best way is using WP_Query. I think your error or plugin error could be that the 'post_type' of childs is not define. WP Query : < global $post; $args = array( 'post_parent' => $post->ID, 'posts_per_page' => -1, 'post_type' => 'products', //you can use also 'any' ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // Do Stuff the_title(); echo "<br>"; the_content(); endwhile; endif; // Reset Post Data wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "custom post types, child pages, hierarchical" }
Theme's page.php and index.php template files are confusing me I was watching a WordPress course, the explainer has `page.php` and `index.php` theme template files. Which means the `page.php` must load the home page, but the home page is loaded with `index.php`! I used his same files, but I have `page.php` loading the home page! How does his setup override it but mine doesn't?
### WordPress Template Hierarchy: You should read about WordPress template hierarchy. This question also has some related answers. ### Typical Case: In your case, **the most likely scenario** is: > The explainer had set the latest posts as the home page (this is the default option) and you have set a static front page as home page. Since his is blog archive, it's being loaded by `index.php` and yours is a page, so that's being loaded by `page.php`. This is just a typical scenario, but there may be other settings that are affecting which template file is being loaded. ### Changing the default setting: If the above is your scenario, then changing the following setting from WordPress `wp-admin -> Settings -> Reading -> Your latest posts` (then `Save Changes`) will make it the same for you and the explainer. Check the screenshot below: ![enter image description here](
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "page template, homepage, frontpage" }
Make a function to run only for CPTs I found an answer where the author comments in the code that the `post_type_link` filter is (only?) for CPTs. How he/she can be sure that his code will run only for CPTs? From the Wordpress Codex: > `post_type_link` is a filter applied to the permalink URL for **a post** OR **custom post type** prior to being returned by the function get_post_permalink. The code in discussion: add_filter( 'post_type_link', 'custom_post_permalink' ); // for cpt post_type_link (rather than post_link) function custom_post_permalink ( $post_link ) { global $post; $type = get_post_type( $post->ID ); return home_url( $type . '/' . $post->post_name . '.html' ); }
Before returning it's result, get_permalink() applies one of 4 filters on the permalink it has generated, depending on the post_type of the post in question: 1. `post_link`, when post_type == 'post' 2. `page_link`, when post_type == 'page', via get_page_link() 3. `attachment_link`, when post_type == 'attachment', via get_attachment_link() 4. `post_type_link`, when post_type is not one of the above (i.e., a CPT), via get_post_permalink()
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, filters" }
How to find the source of the text for wordpress website? I want to change that text I have following code, which is generating the the text on the website. code resides in front-page.php file in the theme folder. <p class="excerpt"> <?php $theExcerpt = get_the_excerpt(); $tags = array("<p>", "</p>"); $theExcerpt = str_replace($tags, "", $theExcerpt); echo $theExcerpt; ?> </p> Let me know if you want more information. Thank you. ![enter image description here](
One thing you can try is going into the page's Edit mode, by pressing "Edit" on that page, and then checking whether that text is by any chance the actual excerpt. If you can't see an "excerpt" section on that page you can go to the top of that page, click "Screen Options" on the top right, and tick the option "Excerpt" (see image). If you find that the excerpt of the page is actually empty, meaning that your theme is probably generating a predefined excerpt when no excerpt is present, you can download your theme to your pc and do an in-file search using the text it is generating (in your case "Lorem ipsum ..."). This way you can find out where it is in your theme's code that the text has been hard-coded. You can use some software like AstroGrep in order to perform the search. ![enter image description here](
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "functions" }
the_post hook is not firing for me I have a super simple requirement here. I have added a meta field to all posts that will allow a url to be used to redirect the post (i have reasons for doing it this way). I am trying to trigger this on the action "the_post", but for some reason it doesnt seem to fire. Here is what ive added function nb_checkredirect($post) { if(get_post_meta( $post->ID, 'nb_postredirect', true ) != "") { header('Location: '.get_post_meta( $post->ID, 'nb_postredirect', true )); wp_die(); die(); } } add_action( 'the_post', 'nb_checkredirect' ); I have checked what gets output to the PHP error log and there doesnt appear to be anything going wrong.
Assuming that your post_meta is being properly added, that the post in question is a real post, and that the value of 'nb_postredirect' is a good URL, I'd try: function nb_checkredirect( $post ) { //don't have to use get_post_meta!* if ( $post->nb_postredirect ) { wp_redirect( $post->nb_postredirect ); exit; } } add_action( 'the_post', 'nb_checkredirect' ); Tested on my own site. *Learned this just while checking up on this question - very nice.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, hooks, actions" }
Change separators in HTML <title></title> tags I'm using WP 4.7.3 and a custom template set (mh-magazine). By default, WP sets a title tag like "Page title" - "Blog title". Now all I want to achieve is to replace "-" into a pipe symbol for layout reasons. So the processed HTMl should look like: My page title | My blog title I thought that this is easy to achieve, but I see I need some help since I'm not an expert in PHP or WP.
It all depends on how your theme's `header.php` is structured, but the most likely way is via the document_title_separator filter, as in add_filter ('document_title_separator', 'wpse_set_document_title_separator') ; function wpse_set_document_title_separator ($sep) { return ('|') ; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "customization, title" }
Change admin post thumbnail size for custom post type only I want to change the size of the featued image for one custom post type only. This is what I currently have: function custom_admin_thumb_size($thumb_size){ global $post_type; if( 'slider' == $post_type ){ return array(1000,400); }else{ return array(266,266); } } add_filter( 'admin_post_thumbnail_size', 'custom_admin_thumb_size'); This function does what I expected but I was wondering if there is any better method to call the custom post type "slider" without touching the others. Thanks in advance
`admin_post_thumbnail_size` takes three parameters: 1. $thumb_size: selected Thumb Size if you do nothing in the filter. 2. $thumbnail_id: Thumbnail attachment ID. 3. $post: associated WP_Post instance So you may make use of these parameters to have a better control in your CODE. Use the CODE like below: function custom_admin_thumb_size( $thumb_size, $thumbnail_id, $post ) { if( 'slider' === $post->post_type ) { return array( 1000, 400 ); } return $thumb_size; } add_filter( 'admin_post_thumbnail_size', 'custom_admin_thumb_size', 10, 3);
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types, admin, post thumbnails" }
Get Posts via Taxonomy Term Name with Space I am trying to retrieve all the post associated with my custom taxonomy term. My custom taxonomy is "Stores". I am using the following code. $posts = get_posts(array( 'post_type' => 'coupon', 'numberposts' => -1, 'post_status' => array('publish', 'unreliable', 'draft'), 'tax_query' => array( array( 'taxonomy' => 'stores', 'field' => 'name', 'terms' => 'New Store', 'include_children' => false ) ) )); My taxonomy term name is "New Store". Just because it has a space in the title I couldn't get any posts associated with it. I tried the same code on a taxonomy term without a space in the title and it worked. Any help will be appreciated. Thanks.
Nevermind, i just extracted the taxonomy term id from name and then extarcted the custom posts from it. Here is the code if anyone is looking: $term = get_term_by('name', 'New Store', 'stores'); $posts = get_posts(array( 'post_type' => 'coupon', 'numberposts' => -1, 'post_status' => array('publish', 'unreliable'), 'tax_query' => array( array( 'taxonomy' => 'stores', 'field' => 'id', 'terms' => $term->term_id, 'include_children' => false ) ) ));
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, custom taxonomy, get posts" }
Why isn't is_page_template() adding a body class? I want to conditionally add a body class depending on what template is being used. I can't figure out why the following code is not working... function damsonhomes_body_classes( $classes ) { if (is_page_template('single.php')) { $classes[] = 'sans-hero'; } return $classes; } add_filter( 'body_class', 'damsonhomes_body_classes'); Thanks all
The `is_page_template()` function is the incorrect function to use in this case as it checks against Page Templates and `single.php` is just a normal template, not a page specific one, usually meant for posts. The function you're probably looking to use instead is `is_single( $optional_posttype )` which will look for singular view of a post type, `post` by default. if( is_single() ) { /** ... **/ } You could also check against the basename if you _really_ wanted to: global $template; $template_slug = basename( $template ); if( 'single.php' === $template_slug ) { /** ... **/ }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "functions, templates, body class" }
Media not actually deleted on disk when click "Permanent Delete" I have uploaded a new docx and pdf through the media library and the procedure is completed successfully. I can confirm that the direct link actually works. The problem is being identified when I try to DELETE PERMANENTLY the files. By clicking on "Delete Permanently", the file record is deleted from the media library, nevertheless the actual file (and its direct link) still resides on disk. On the other hand, Wordpress returns a message that the deletion was completed successfully. Can you suggest me possible steps to debug the above-mentioned prcedure? Wordpress 4.7.3 currently resides on IIS 8, with PHP 7.0.x. I have checked some possible user permissions for IUSR, and currently on files is being given full control. Thank you, Chris
So, after several attempts... it is a problem (or a feature) of the WPML multilanguage plugin. 1. To start with, I have set up correctly the user permissions, as @WebElaine mentioned. Just in case something was not configures properly. More information on the following articles: Permissions to wp-content folder in Windows Server 2012 < < 2. In my case, I had installed the WPML Media plugin. With the default behaviour, on each media file that is being uploaded, the plugin creates as many database records as the installed languages. When someone navigates in the media library, and "deletes permanently" a file, it just deletes the **database record** and not the **physical file** on disk. The user should **browse each language** (on back-end, the flag on the upper bar), and "delete permanently" the specific file for each language. More info here: < < When the last record is being deleted, then the physical file will be deleted also. Hope it helps! :) Chris
stackexchange-wordpress
{ "answer_score": 16, "question_score": 6, "tags": "uploads, media library, permissions, iis" }
Wordpress doesn't include css I want load a custom css in the `index.php` file, this is my code in `function.php` if(! function_exists('basictheme_styles_scripts')) { function basictheme_styles_scripts() { wp_enqueue_script('jquery'); wp_enqueue_style('basictheme-opensans', '//fonts.googleapis.com/css?family=Open+Sans'); wp_enqueue_style( 'basictheme', get_template_directory_uri().'/style.css'); } } add_action('wp_enqueue_scripts','basictheme_styles_scripts'); but perhaps something is wrong, beacause my index doesn't load it
You've placed the relevant code inside `function.php`, but WordPress loads `functions.php` You're also missing some indenting which makes syntax errors much more likely to occur, and you can save some typing by using `get_stylesheet_uri()` instead of `get_template_directory_uri().'/style.css'`
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "php, css" }
How to add a style to taxonomy edit page Is there anyway to load a custom style in specific taxonomy pages? for example these two pages: wp-admin/edit-tags.php?taxonomy=news-category&post_type=news wp-admin/term.php?taxonomy=news-category&.. I added a style to admin but other pager got edited too, how can we load the style when in these two pages of custom post type taxonomy?
You can do it like this: add_action ('admin_enqueue_scripts', 'wpse_style_tax') ; function wpse_style_tax () { // these 3 globals are set during execution of {edit-tags,term}.php global $pagenow, $typenow, $taxnow ; if (!in_array ($pagenow, array ('edit-tags.php', 'term.php')) { return ; } if ('news' != $typenow) { return ; } if ('news-category' != $taxnow) { return ; } wp_enqueue_style ('wpse_my_handle', 'path_to_css_file', ...) ; return ; }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "custom taxonomy, wp admin, wp enqueue style" }
What could be the reason that i can't access to the other pages of my localhost wordpress website except the homepage? I can't figure this out on google. I was getting the following error. ![enter image description here](
your .htaccess likely wasn't inited. You can go into your settings/permalinks and hit save and this will flush the settings for you and it should work.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "404 error, local installation" }
Wordpress add_admin_page not working even parameters are correct? function Y_add_admin_page(){ add_menu_page('Y-07 Theme Options','Y-07','mange_options','y-admin','Y_admin_create','',110); } add_action('admin_menu','Y_add_admin_page'); I had used is_admin function it is returning false even I am an adminstrator
Please try this add_action('admin_menu','Y_add_admin_page'); function Y_add_admin_page(){ add_menu_page( 'Y-07 Theme Options' , 'Y-07' , 'manage_options' , 'y-admin' , 'Y_admin_create' , '' , 110 ); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugin development, theme development" }
how to make custom post with "publish" default functionality not save in draft? This is my custom post type code everything working fine but when i publish post, the post is being saved in draft mode. $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => $slug), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => 4, 'supports' => $supports, 'taxonomies' => array( 'category' ), ); register_post_type(self::$PostTypeName, $args);
Use 'wp_insert_post_data' filter hook for that kind of problem add_filter('wp_insert_post_data', 'filter_post_data', 99, 2); function filter_post_data($postData, $postarr) { if ($postData['post_status'] == 'draft') { $postData['post_status'] = 'publish'; } return $postData; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, posts" }
remove categories from product Is is possible to remove all the categories from a product in WooCommerce? I have written a script which is run every time when a product is added/updated via WP-All-Import, but there are some wrong categories on the products, which I want to clean, deleting all the categories or products is not an option, so I want clear the categories on the products and let my script decide which categories to add to this product.
I have found the solution, actually it is very simple: $terms = get_the_terms($product_id, 'product_cat'); foreach($terms as $term){ wp_remove_object_terms($product_id, $term->term_id, 'product_cat'); } This code get all the therms with the 'product_cat' taxonomy, with a foreach loop I remove all the items.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "woocommerce offtopic" }
How to set the mainpage of a custom post type? I just created a new custom post type to contain all the individual posts of the event im hosting. I want the slug for each post to be: **myurl.co/conference/programitem** I already got a page with the url: **myurl.co/conference/** which i want to be the mainpage of this particular slug. (On this page some other information about the event is already displayed and it will include links to the individual program items etc) However, i got a conflict now that as soon as i created the custom post type, **myurl.co/conference/** leads to the first post of the newly created post type instead of the already existing page that i was planning to use as the mainpage. tldr; How do i prevent the **myurl.co/conference/** url from going to the first post and instead go to the page i was planning to use for that? And have **myurl.co/conference/programitem** go to their own posts. ps. I dont want to change the url to for example myurl.co/conference0/
When you register the custom post type you need to include `has_archive` set to the slug where you want the archive. You also need `rewrite` set to the slug prefix. It's probably easier to understand the code rather than my wording of it: Your code should look something like this now: register_post_type('conference', ... 'public' => true, ); You need to update it to: register_post_type('conference', ... 'public' => true, 'has_archive' => 'conference', 'rewrite' => array('slug' => 'conference'), ); You may need to use `unregister_post_type` first, to clear it out, and then re-register with your updated function. After the new version is registered, visit your permalinks page to update permalinks, and you should then have both an archive at **myurl.co/conference** and individual posts at urls like **myurl.co/conference/program-item-slug**.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, php, posts, pages" }
Recent posts and first featured I have the code below to list the recent posts on my site. It's working fine. I need to style differently the first post (bigger image and bigger title). Any idea how ? <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'post', 'posts_per_page' => 10, 'paged' => $paged ); $wp_query = new WP_Query($args); while ( have_posts() ) : the_post(); ?> <div class="main-content span12"> <div class="main-content span4"> <!--Image article--> <img src="<?php the_post_thumbnail_url( 'medium' ); ?>"> </div> <div class="main-content span8"> <!--Titre article--> <h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> <!--Extrait article--> <?php the_excerpt(__('(more…)')); ?> </div> </div> <?php endwhile; ?>
The easiest way would be using CSS, so you don't have to change the PHP. Assuming you have a or some other wrapping element that contains all your posts, you could use something like .main-content.span12 img { width:50%; height:auto; } .main-content.span12 h4 { font-size:1em; } .main-content.span12:first-child img { width:100%; } .main-content.span12:first-child h4 { font-size:2em; } `:first-child` will get only the first child of the parent element - so it will apply to only the first `<div class="main-content span12">`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "posts" }
Unable to get specific value from post meta I am using `get_post_meta()` to retrieve a custom meta field value from a given post. The custom meta box has a parent checkbox which has 3 child checkboxes. I want to get the values of both parent and child. * Parent checkbox Enable Protection for this post * Child checkboxes: (a) Level 1 (b) Level 2 (c) Level 3 here is the screenshot of the metabox. < The code I am using is: $meta = get_post_meta( '8142', '_key_value', true ); foreach( $meta as $m ){ echo $m['protect']; echo $m['selectedlevels']; } But it only echo the `$m['protect']` which is also the parent checkbox. How can I output its child checkboxes too? if I `var_dump`, it returns the following value: `array(2) { ["protect"]=> bool(true) ["selectedlevels"]=> array(1) { [0]=> int(2) } }` Any help would be highly appreciated. thanks in advance :)
Based on your `var_dump()` I can only assume the checked values are in the `selecteclevels` array which you can get by looping through the array: foreach( $meta['selectedlevels'] as $level ) { echo $level; } Or using array indices: `echo $meta['selectedlevels'][0]`. Note, `get_post_meta()` may return nothing, and you should check if the `selectedlevels` index even exists your returned variable.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom field, query posts, post meta" }
where can i find the login page in wordpress and add my header to it Where can I find the wp-admin login file so i can add my header to it i can find it i looked in the wp-admin folder for `login.php` or anything like that but can not find it, i also tried looking in the `index.php` under wp-admin for it but still could not find it. I want to add my site header to it, via `get_header();`. i also tried going into `wp-login.php` and adding `get_header();` right under the `<body>` tag Please help thank you
Change the Login Logo To change the WordPress logo to your own, you will need to change the CSS styles associated with this heading: <h1><a href=" title="Powered by WordPress">Your Site Name</a></h1> From <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "customization, wp admin, login" }
Search isn't displaying all results On one particular site, when I do a search, not all relevant results are returned. Example: Post Title: This is xxx Post Content: Hello World, this is xxx. When searching for 'xxx', the post isn't returned in the search results. Is this expected behaviour, and how do I fix this? This is the code for the search template: <?php get_header(); ?> <div class="vw-page-wrapper clearfix"> <div class="container"> <div class="row"> <div class="vw-page-content col-md-8" role="main"> <?php do_action( 'vw_action_before_archive_posts' ); ?> <?php get_template_part( 'templates/post-box/post-layout-'.vw_get_archive_blog_layout() ); ?> <?php do_action( 'vw_action_after_archive_posts' ); ?> </div> </div> </div> </div> <?php get_footer(); ?>
I don't know what the problem exactly was, but I solved it by writing a custom search query: <?php $args = array( 's' => $_GET['s'], 'post_type' => array( 'post', 'page'), 'post_status' => 'publish', 'posts_per_page' => -1 ); $custom_search = new WP_Query( $args ); if ( $custom_search->have_posts() ) { while ( $custom_search->have_posts() ) : $custom_search->the_post(); ?> <div class="block-grid-item"> <div class="entry-content clearfix pagecategory"> <h2 class="newstitle"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> </div> </div> <?php endwhile; } else { ?> <h2>Your search didn't return any results.</h2> <?php } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "search" }
Where do the section input fields values are stored in database register_setting('Y-sidebar-options','picture'); where do the option group name stored in database .
The option group (1st param to register_setting()) is **not** stored anywhere. The only use for option groups is to output a couple of hidden fields and a nonce, via a call to settings_fields().
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development, theme development, database" }
Add custom image size not working I want to add a custom image size to my child theme. The base is the Penscratch theme, and it has it own image sizes defined: function penscratch_setup() { /* ... */ add_theme_support( 'post-thumbnails' ); add_image_size( 'penscratch-featured', '400', '200', true ); /* ... */ } And if I made some changes here (base functions.php), everything work as it should, But the point is to make it done in child-Theme, I'm writing it the same way but for some reason it's not working: add_action( 'after_setup_teme', 'add_custom_img_sizes'); function add_custom_img_sizes() { add_theme_support( 'post-thumbnails' ); add_image_size( 'category-thumbnail', '300', '200', true ); } if I use then the 'category-thumbnail' in my template, it is displaying the full-sized image, not the cropped one, what is going wrong here?
After you add a new image size, you have to regenerate the images for that size. The Regenerate Thumbnails plugin comes in handy for this purpose.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "functions, images" }
What hook is the currently active theme's functions.php file loaded on? At which point of hook execution is the currently activated theme's `functions.php` file loaded?
It is included from `/wp-settings.php` right after the action `setup_theme`. Line number 423 as of WordPress 4.7
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "themes, hooks, actions, wp load.php" }
How to filter $content in shortcode function I would like to filter the $content in my shortcode function so that all I get is the shortcode. I am trying to nest one shortcode inside another dynamically. Here is my code function add_slider ($atts, $content='') { $atts = shortcode_atts(array ( 'align' => 'center', 'width' => '50%', 'height' => 'auto' ), $atts); /* foreach($videos as $video) : $return.='<li><a href="'.get_permalink().'">'.the_title("","",false).'</a></li>'; endforeach; */ if( has_shortcode( $content, 'video' ) ) { $content = do_shortcode($content); return '<ul class="bxslider">' . $content . ' </ul>'; } else { return '<ul class="bxslider"> <li> No Videos Found In Slider </li> </ul>'; } } add_shortcode('slider','add_slider' );
I solved my own issue. I needed to filter out all the `<br>` and white space between my shortcode tags. WP was auto adding breaks which my functions was adding to the output of my shortcode. So I used the strip tags function to filter the $content of my shortcode $content = strip_tags($content); I added this to my shortcode function and it worked like a charm! Thanks to the people who pointed out the potential issues with the previous answer.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "functions, filters, shortcode" }
Wordpress admin-ajax.php I was thinking.. My admin-ajax.php file is slowing down my website a lot.# What about if remove it? Is this file important enough? Would it be any security or funcionality issue after deleting it? Would my website be faster? Any feedback would be appreciated
File name should be `admin-ajax.php` This file handles all the ajax requests. So, you should never remove this file. Many features will stop working like autosave and many other that uses ajax if you remove this file.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php, functions, theme development, wp admin" }
Custom post url in search.php isn't the correct rewrited url I'm trying to get the rewrited URL of my custom post type on the search result page by using: `echo get_permalink(get_the_ID());` This returns the basename of my site plus the post slug, which isn't correct since I've rewritten the URL using the `'rewrite'` argument in my `register_taxonomy` function. On every page, using `get_permalink` in the post loop I get the correct URL, except on the search results page. Does anyone have an idea how to solve this?
Solved, it was an issue with assigned parent- and subcategories. Because I'm using the 'WP All Import' plugin connected to Google Drive, posts are automatically imported. Since some of the posts don't have categories assign in the Google Drive document, 'WP All import' doesn't assign a category on importing the data. For some reason this has resulted in duplicate content, importing already existing posts but without a category. Because the latest imported posts are without category and ordered descending by date on the search page, I was under the impression that there was something wrong with the permastructure.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, url rewriting, search" }
Trying to list user and post information from (wp_includes/post.php ) causes Fatal error I Got Fatal error: > Call to undefined function get_currentuserinfo() I tried using: * `get_userdata( $userid );` * `$current_user = wp_get_current_user();` * `$current_user = get_currentuserinfo();` in wp_includes/post.php I need to update a table whenever a post is published in admin portion and I tried to retrieve above details but it causes an error.
Please revert your WP core file and create a plugin instead. For this type of functionality, you can use the Publish Post hook. Assuming your custom table is in the same database as WordPress, and you want to save the email address of the current user: add_action('publish_post', 'update_my_custom_table'); function update_my_custom_table() { $current_user = wp_get_current_user(); $email = $current_user->user_email; global $wpdb; $addInfo = $wpdb->insert('wp_custom_table', "$email"); } Hopefully this will get you started down the right path, so you can insert whatever data you're trying to add. There may be a better way than adding your own table, depending on what you're trying to accomplish, but you didn't mention much about your goal for the data.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp admin, admin" }
Migrate a Non Wordpress database to wordpress I have a MySQL database with 71 tables. It houses news, galleries, slideshow data, page content, products, customers, shipping, discount codes, ( basically a full store build on a PHP shop). I want to migrate over to WP. I'm new to wordpress, how easy/difficult will this be? I can do a SQL dump of the database easily. But how easy will it be to map the tables, structure and data to wordpress tables? Is there any plugin that can help?
Unfortunately it's not really and easy process. It's not about just having a table. The tables in WordPress will have different names, fields, and relationships than the cms you're pulling your table from. That's just for the content. Then to mirror appearance will definitely be starting over all the same. It would likely be a much easier process to create a new wordpress install with a clean install and manually set up new pages with the old content. Without knowing more about your current CMS or how much content you have I'd strongly suggest you go this route. Sorry for the bad news, but good luck and you'll love wordpress. UPDATE BASED ON COMMENT While by no means an endorsement, you may want to check out wpallimport. It will let you set up imports based on CSV files and let you import them into any post type. It doesn't have that steep of a learning curve, but it will even let you attach photos to the posts to update!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "database, migration" }
Tracking the number of shortcodes for a list? I want to have a list of my top 10 favorite resources. Each resource is going to be in a shortcode [resource name="Resoruce Name" link="http:/"]Why I love the resource[/resoruce] However, I want to number them, and I'd like to just write them in the order I want and re-organize as time goes on without having to change the #s. Can I use some type of counter variable in the Functions.php to count?
Wrap an `<ol>` around them and have your [resource] shortcode create an `<li>` for each one. Editor view: <ol> [resource name="Resource" link=" I love it[/resource] [resource name="Another Resource" link=" I love this[/resource] </ol> HTML output: <ol> <li><a href=" I love it</p></li> <li><a href=" Resource</a><p>Why I love this</p></li> </ol>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, shortcode" }
Keep getting same permalink with WP_Query? I have this code below, and I wish to show each link of each post, but I keep getting same link to all posts which is the link of the page. $args = array('posts_per_page' => 5,'order' => 'DESC'); $rp = new WP_Query($args); if($rp->have_posts()) : while($rp->have_posts()) : $rp->the_post(); the_title(); $link=the_permalink(); echo '<a href="'.$link.'">Welcome</a>'; echo "<br />"; endwhile; wp_reset_postdata(); endif; Thank you.
Don't forget to use `esc_url()` echo '<a href="'. esc_url( $link ).'">Welcome</a>'; Also try this: `get_permalink( get_the_ID() );`
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "posts, wp query, permalinks, links" }
BBPress changing default group activity Dear WordPress community, I am pretty new to WordPress and I am running into an issue with **BBPress** , when I open a group there is a small pulldown on the right side of the page where I am able to change the view of the group activity. By default, this pulldown is filled with " _\--Everything--_ ", I want it to select and load " _Updates_ " instead of " _\--Everything--_ " as shown in the screenshot. ![enter image description here]( Is there anybody able to push me in the right direction for this issue? Best regards, Kai
After searching a bit more I found this plugin: < It will let you alter these settings without modifying the plugin itself. Hope this will help other users in the future that will land here through a search.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "filters, bbpress, customization" }
Custom plugin init action causing general slowness I'm developing a custom plugin which connects to salesforce and needs to check that the connection hasn't expired on each page refresh. If it does expire, it reconnects etc. So I am doing this on an init action, but I've noticed a very significant performance hit doing it this way. Particularly loading images from the media library. My understanding now is that init fires with every request, so on a page with 20 images, it will fire at least 20 times??? Is this correct? So obviously init isn't the best for this purpose, what should I be using? Kevin
If you want your function to fire only once, you can use other hooks. `wp_head` might be useful in your situation since it is fired before the rest of the template is rendered. `template_redirect` is also fired before rendering the template. If the sequence doesn't matter to you, you can fire it at last using `wp_footer` or `get_footer` hook.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, plugin development, actions" }
How to insert a text in all pages and posts before or after specific places? I have this simple code below: function func1() { echo "this is amazing"; } add_action('reko_hook','func1'); Now, I know that I could use **_reko_hook();_** either inside **_index.php_** or **_page.php_** where I want, but I was wondering if there are more pre-defined hooks such as ' ** _init_** '. For example, I could do add_action('init','func1'); but it will echo **_this is amazing_** before the header, The question is, if there are other pre-defined hooks to specify the location of the function output **_this is amazing_** to be placed: 1. After the header, before the Page/Post title. 2. After the header, after the Page/Post title. 3. Before Footer. 4. After the Footer. Thank you.
You can add to before or after the content as well in a similar fashion. I use this code: function rt_before_after($content) { $beforecontent = 'This goes before the content.'; $aftercontent = 'And this will come after.'; $fullcontent = $beforecontent . $content . $aftercontent; return $fullcontent; } add_filter('the_content', 'rt_before_after'); You could use it similarly with the_title,. The reko_hook() you have likely came with your theme or a different plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "functions, init" }
Tried in different ways but sidebar not working? function Y_widget_register(){ register_sidebar(array( 'name'=>esc_html__( 'Sidebar', 'Y-07' ), 'id'=> 'y-sidebar', 'description'=>'Dynamic Right Sidebar', 'before_widget' => '<section id="%1$s" class="y-widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h2 class="y-widget-title">', 'after_title' => '</h2>' ) ); } add_action('widgets-init','Y_widget_register' ); I tried different styles previous versions too but not working, what possibilities making my code not to work.
add_action( 'widgets_init', 'Y_widget_register' ); You have a typo - use underscores. Here is the working piece: function Y_widget_register() { register_sidebar(array( 'name' => esc_html__('Sidebar', 'Y-07'), 'id' => 'y-sidebar', 'description' => 'Dynamic Right Sidebar', 'before_widget' => '<section id="%1$s" class="y-widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h2 class="y-widget-title">', 'after_title' => '</h2>' )); } add_action('widgets_init', 'Y_widget_register');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development, theme development, actions" }
Retrieving an intersection of two terms from two different custom taxonomies via API Running the current version of the API via the WP core and the rest-filter plugin I'm trying to retrieve a set of posts at the intersection of two terms from two different custom taxonomies. Initially I thought `posts?filter[tax1]=term1&filter[tax2]=term2` would do the trick, but sadly that is not the case. Is there a way of doing this via the API (with or without the rest-filter plugin) or do I need to do something to `rest_query_vars` (which I'm also a little unsure about)?
Currently there is not a way to do this via the core API, though this could change in the future. To retrieve this form of content you have to create a new endpoint.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom taxonomy, rest api" }
Class 'WP_Widget' not found I am learning Wordpress development with a tutorial where we learn to create a widget, it is asked to create a file named `newsletterwidget.php` with the following code, but it does not say in which folder to put it: class Zero_Newsletter_Widget extends WP_Widget { public function __construct() { parent::__construct('zero_newsletter', 'Newsletter', array('description' => 'Un formulaire d\'inscription à la newsletter.')); } public function widget($args, $instance) { echo 'widget newsletter'; } } So, as WP_Widget class is created in `wp-includes\class-wp-widget.php`, I decided to put `newsletterwidget.php` in `wp-includes` but I get the following error: > Fatal error: Class 'WP_Widget' not found in C:\xampp\htdocs\wordpress\wp-includes\newsletterwidget.php on line 5 Thank you
You should never work on core files which are inside wp-admin and wp-includes folder. You'll be just working on wp-content folder. If you're developing a plugin, you can directly put the code in your main plugin file or you can put the file inside of your plugin folder and include that file in the plugins main file. Or if you're working with a theme, you can put the code directly in functions.php or create the php file inside your theme folder and include that file in functions.php
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "php, widgets" }
I made a my own theme to WordPress and Admin Menu missing from frontend I made a my own theme to WordPress and Admin Menu missing from frontend. How to fix this?
First of all, you should keep the below code in your theme( header.php file ). <?php wp_head(); ?> Something looks likes the below in header.php file <!doctype html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?php wp_head(); ?> </head> Lastly, You need to put the following code in your footer.php, before closing tag <?php wp_footer(); ?> The code looks like these <?php wp_footer(); ?> </body> </html>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "theme development" }
How to add a custom.js file for a child-theme in a swift way? How to add a custom.js file for a child-theme in a swift way? By "swift" I mean to a way that won't involve changing anything in the parent theme and will be minimal by means of coping and modifying any settings file from the parent theme to the child theme. Adding the following code to the `add_action` function right after `wp_enqueue`_style function call in functions.php, causes the site to crash (I'm not a PHP programmer and as for now, don't know how to debug this): wp_enqueue_script( string $handle, string $src = '/custom.js', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false ); This also doesn't bring any effect (even though the site doesn't crash): wp_enqueue_script( 'custom', get_stylesheet_directory_uri() . '/custom.js');
That worked for me: wp_enqueue_script( 'YOUR_SCRIPT_NAME', get_stylesheet_directory_uri() . '/YOUR_SCRIPT_FILE.js', array(), '4.7.3', true ); ## Notes: 1. I usually name the script just as its file name. 2. You don't have to use the version number 4.7.3, but you do need to write some plausible version number (like of your Wordpress core version) or the keyword `null` instead.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "javascript" }
WordPress incorrectly redirects to local IP address? I have my wordpress server set up using php, mysql, and apache on my raspberry pi. I also have a dynamic dns hostname and configured my router's port forwardiing settings. When trying to access my server from outside of my local LAN, when I type in my dynamic dns host, (for example, my phone on 4G mobile network or at school), the site incorrectly redirects to the server's local IP address: 192.168.0.18 so the page fails to load up. This is very weird because I also have owncloud set up on my pi and in the same condition I try to access mydynamicdnshost/owncloud, it doesn't redirect me to local IP and the page loads up successfully. I know this is a really basic problem with wordpress configuration but I simply cannot fix it. So does anyone know that please answer my question. Many thanks!
Change the Site URL in Options Table. UPDATE `wp_options` SET `option_value` = 'YOUR_SITE_URL' WHERE `option_name` = 'siteurl' OR `option_name` = 'home'; Also change the static URLs in your post content. UPDATE `wp_posts` SET `post_content` = REPLACE(post_content, '192.168.0.18/YOUR_LOCAL_SITE_URL/', 'YOUR_SITE_URL/'); Don't forget to change the table prefix if its not 'wp_'. * * * **Edit :** Access PHPMyAdmin of your server. Contact your Hosting Provider if you are not aware of this. Select your WordPress Database & Access wp_options table. And change 'siteurl' && 'home' attribute values to your Live Website URL. Hire a developer if you are not sure what you are doing ! ![enter image description here](
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "server, apache, linux" }
What is the correct term for a tool that filters content based on metadata? I am creating a resource library for students at my online school that will be searchable with metadata. Many sites such as WorldCat have a tool on the left-hand side where you can filter or refine content (look at the div tag "FormatRefinement" in the example) based on metadata. What is this functionality called? Intuitively, it would seem to be called a 'content filter' but any search for filters brings me to the WordPress Codex where it discusses 'hooks and filters.' I've tried searching for the correct terminology myself but, after several months, no luck. Thank you.
After additional research, the answer appears to be that the term **"taxonomy"** encompasses the two sorting tools most common in WordPress. Those are **categories** , which can be hierarchical, and **tags** , which cannot have a parent-child relationship. A simple example would be a custom post type called _cafes_ in which you might have parent categories such as districts, child categories such as neighborhoods, and various tags to describe the general atmosphere.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, search" }
How to find list of all functions bind to a particular hook from my plugin? I want to remove all actions attached to admin_notice hook in my plugin at the time a user updates the plugin. Is there any way to find the list of functions attached to admin_notice hook by my plugin?
You can use this Plugin ! It supports following features for Hooks * Shows all hooks fired on the current request, along with hooked actions, their priorities, and their components * Filter hooks by part of their name * Filter actions by component (WordPress core, Plugin X, Plugin Y, theme) <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, filters, hooks, actions" }
FTP installation of WordPress The client am working with want a website built and I discovered the site use for hosting. The problem I am having is that they want a WordPress site. What I am used to is installing WordPress of the domain in question and then start developing. But in this case they only want to provide a FTP login. Wouldn't they still have to provide the cpanel login information so I can install WordPress using this hosting provider or should I ask them to install a WordPress and provide you the WordPress admin login details?
FTP login is more than enough to install wordpress. You just need to upload your wordpress's root folder content (not root folder itself) via FTP and then open your site's admin section via browser something like this ` Then you will see wordpress installation step. Follow that steps and your wordpress installation is done. **NOTE** If you are uploading wordpress from local or from other domain (not fresh setup) then don't forget to change database name, username, password, host in `wp_config.php` available in root folder of wordpress. Following steps must be done only after you have a database ready to install wordpress because on installation you need to specify database name, username and password. And database can't be created with FTP.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "ftp" }
How can I write a formal sql query to get data from a custom table I have created a custom page in wordpress admin panel with the help of `add_menu_page` and a custome table in database with the name `wp_doners` I want to fetch data from that table in that page so I tried to get help from videos etc.. but could not succeed. I can state my purpuses that i want following results.. $result = mysqli_query($connect, "SELECT * FROM wp_doners") while($row = mysqli_fetch_array){ echo $row["id"].' - '.$row["name"]; } please anybody help me to solve this issue.. I am stucked here..
You have to call global instance of `$wpdb` first for writing custom queries. For example: ` global $wpdb; $tableName = $wpdb->prefix . 'table'; $result = $wpdb->get_results('SELECT * FROM '.$tableName); ` For more details you can refer this _WordPress Codex_ page
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "mysql, sql, admin menu" }
Woocommerce Free shipping method I would like add new functionality on my site which requirement is given below. I spent to much time in google but I didn't find any plugin. Requirement: **ON CHECKOUT Page, I want an option to choose "Bring to _____ event verses shipping." and then user don't have to pay shipping.** Is there any plugin which fulfilled my requirement?
I hope this plugin will help you. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, woocommerce offtopic" }
When did wordpress switched requirements to php7? I cannot find this information anywhere. Does any of you knows when exactly (from what version on) they switched system requirements to PHP 7? EDIT < When did wordpress start recommending php7? From what of the wordpress versions? Or what date (more difficult, and I don't strictly need).
The currently **required** minimal PHP version is still **5.2.4+**. The **recommended** version is 7. According to archive.org since December 2, 2016. Note that many plugins and themes need at least PHP 5.4 or newer nowadays, and that PHP versions below 5.6 do not get security updates anymore and are therefore probably not safe for production. WordPress doesn't use any of the newer PHP features, but it does work with the latest PHP version.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "php, wordpress.org" }
Adding a simple Javascript file with a plugin I just want to create an alert box when a page with a post is reloaded. <script type="text/javascript"> window.alert("alert"); </script> And here is the php code i wrote to load the js. function alert_js(){ wp_enqueue_script('alert_js', plugins_url( '/alert.js', __FILE__ )); } add_action('the_post', 'alert_js'); I'm sure that it successfully finds the script in right place(I checked the page source.). But somehow it acts like there is no javascript included. What I'm missing there?
I think you are missing the trigger... your javascript should be something like this in order for it to trigger when the page is loaded: $( document ).ready(function() { alert( "ready!" ); });
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, php, javascript" }