INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Use different categories for a custom post I was wondering if it was possible not to mix the categories across my different custom post ?
Do you mean having different taxonomies for your custom post types? If so, you can define custom taxonomies and apply this taxonomies only to the post types you want. If the custom taxonomy has "hierarchical" argument set to true, the taxonomy will be works the same way categories do. register_taxonomy( 'my_taxonomy_name', 'my_custom_post_type', array( 'hierarchical' => true ) ); //And then register_taxonomy_for_object_type( 'my_taxonomy_name', 'my_custom_post_type' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, custom taxonomy" }
Is there a way to implement a commenting system such as that on medium or sitepoint in WP? Both Medium.com and SitePoint allows users to comment on individual paragraphs. I'm not sure how it's implemented but is there a way to do something similar in wordpress? See screenshots below to see what I mean: !Medium comment system !SitePoint comment system Thanks in advance for the help.
I don't know Medium.com but sitepoint.com use Wordpress so the answer to your question is quiet obvious: YES, there is a way to implement that in wordpress. You should make other types of questions. I think this the implementation used by sitepoint is here: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "comments" }
why some permalinks adding characters/ruining links I am using a gallery to link to some sub categories. Some of the links within the category work exactly how they should. However there are a few that are adding strange characters on the end, I've re-done the permalinks but it still does it, you cannot see the extra characters in the link section of my gallery admin. Obviously by adding these characters, it is preventing the link from working and giving me the 404 message. It is vital to my website that my links work. Can anybody think of a reason why they would not? I have tried disabling plugins and also looked for invisible characters. "%20%E2%80%8E" variants of this are what is being added. Really hoping someone can help me to solve this! Thanks.
Chances are you are copy+pasting the links in, correct? Depending where you are copying from, they could be filled with hidden space characters, like `<wbr>` in the actual HTML (if you copy from a website) which offers a break point. You need to paste these links into TextEdit, or Notepad, or Event the browser address bar to make sure no spaces are being stuck in there by mistake.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "permalinks, links, characters" }
Use different template than author.php for get_author_posts_url() I have a client that wants two pages for each author profile: First Page - has user info, bunch of social media links, etc. Using author.php for this. Second Page - list of author posts I've built everything, and here's my question: **Is there a way to have get_author_posts_url() use a template other than author.php?**
There is a filter called `author_link`. You can use that change the URL to whatever you want. add_filter( 'author_link', function ($link, $author_id, $author_nicename) { var_dump($link, $author_id, $author_nicename); // debug return $link; // return your modified URL }, 1,3 ); The question does not have enough detail to allow for more specific code. You can use the `template_include` hook to alter the template that loads in much the same way as the above code alters URL. function author_archive_wpse_112852($template) { if (/* not sure what your conditions are */) { $template = get_stylesheet_directory().'/diff-author-template.php'; } return $template; } add_filter('template_include','author_archive_wpse_112852');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "author template, template hierarchy" }
Do something when user creates post (that's pending) How do i do something when a (normal) user creates a post (that is submitted for approval) I currently have: function emailinvestment( $new_status, $old_status, $post_id ) { if ( $old_status != 'new' && $new_status != 'pending' ) { // Do something (not working atm) } } add_action('transition_post_status','emailinvestment', 10,3); Thanks for taking a look at this one :)
Found it! The following line: if ( $old_status != 'new' && $new_status != 'pending' ) { Should be: if ( $old_status != 'new' && $new_status == 'pending' ) { Thanks for the help guys!
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "functions, email, actions, post status" }
problem with pagination in custom permalinks I have set custom permalinks: /%category%/%year%/%monthnum%/%day%/%postname%/ When I use the following url: < works fine. However, when I click on the second page, I get a 404 I have tried this on a clean site. This also occurs with a standard theme
One solution: Use the Category Pagination Fix plugin Here is the reference: < (lengthy explanation)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, pagination" }
Optimising a big Wordpress site I'm looking at optimising a rather large site I've been adding to and adding to. The database has become pretty big (maybe 100,000 posts) and it has started slowing down somewhat and giving me "Mysql has gone away"errors. I've been reading about database optimisation and have ready some people saying you should only be looking to use 1-15 queries on a page. Do people think the suggestion that only a handful of queries should be used on any page? Am I correct in thinking that every time I use a Wordpress function such as get_permalink() I am creating a new query and new connection the database? I have some loops in there that literally loop through 100+ users at a time and use functions such as get_user_meta() in these loops - so would this mean I am literally making 100 database queries or are they somehow cached in Wordpress? Thanks
Looking a the source code of get_permalink(), that function not always generates additional queries. It depends on the particular situation. get_user_meta() is always performing aditional queries although they can be stored in wp cahe. Take a look into Save queries for analysis and this helpful plugin. You will be able to see the total number of queries, time taking by each one and other useful information that will help you to know if using a especific function is generating aditional queries or not.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development, database, optimization" }
how to get number of posts in a category on a specific date I want to get the number of posts for each category on a specific date. I think I can do the following: \- get a list of categories \- start loop \---create a query for each category and specific date loop and count posts \- end first loop Is there any easier way to do this? I plan to put this in the php code widget. Note I have quite a few categories
You would want to use something like this: $query = new WP_Query( 'year=2013&monthnum=12&day=20&cat=5' ); // change cat=5 to the ID of the category you want to query from. // change year to the year you want // change monthnum to the month you want // change day to the day you want // start the loop while( $query->have_posts() ) : $query->the_post(); // do loop stuff endwhile; wp_reset_postdata(); Above says get all posts that has ID of 5 for category and the year of 2013 and month is 12 (December) and day is 20.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, loop" }
How to filter by custom post type in taxonomy archive pages I have two custom types. One called "Questions" and other called "Files". They both share a custom taxonomy called "Types". Everything works fine, however if I go to the "Types" link inside my Wordpress admin and click on any category, it lists all the items, both in "Questions" and "Files". Is there a way to construct a link so I could just query a specific type of one custom type instead of both? Thanks a lot!
That is the normal behaviour. If you go the archive of one taxonomy term you will get all posts, of any type, with this taxonomy term. One solution can be, for example, adding ?custom_type=files or ?custom_type=questions to your URLs and alter the main query in the pre_get_posts filter: add_action( 'pre_get_posts', 'my_pre_get_post' ); function my_pre_get_post($query){ if(!empty($_GET['custom_type'])){ //limit the filter to frontend, main query and archive pages if($query->is_main_query() && !is_admin() && $query->is_archive ) { $query->set('post_type',sanitize_text_field($_GET['custom_type'])); } } } If you want to go further you can write custom rewrite rules and add query vars to have those URLs be "pretty".
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types, wp query" }
help for user login please help, I have to restrict some users based on the value of some metadata.for eg:if the account is not verified by admin(a metafield like "adminveri" will be zero), then the user should not login....please help me.. this is what i have done so far... add_filter('authenticate', 'check_login', 100, 3); function check_login($user,$username,$password,$uid) { if(!empty($user)) $user_data=$user->data; $adminveri=get_user_meta($uid,'admin_status'); $emailveri=get_user_meta($uid,'email_status'); if($adminveri[0]==0) or $emailveri[0]==0 ) { return null; } else { return $user; } } this code dont allow anyone to login...Also what is the difference between add_filter and add_action?
Add the folowing to your themes's functions.php file. add_action( 'wp_login', 'wpse_112895_validate_user', 10, 2 ); function wpse_112895_validate_user( $login, $user ) { $meta = get_user_meta( $user->ID, 'adminveri', true ); // not verified, log them out! if ( $meta != 0 ) wp_logout(); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, login" }
Installing local to live WP into subdirectory I am having a bit of trouble moving a local WP site live and into a subdirectory. I want a static homepage for now (index.html in the root folder) while I work on the live site (would be found in root/folder/, so website.com/subfolder/). Following these steps I've had success installing WP into the root folder, but it doesn't work for a subdirectory. I was wondering if someone could walk me through how to get it to work, so I have a static homepage and am able to work on the WP site live. My host is dreamhost.
Since you want to test out your existing(local) site on the server; you have done the right thing as far as I can see on pastebin except for 1 thing On step 10 - you replaced all occurances of "localhost" with your servername. Instead you should have replaced it with servername/directoryName. If you still have issues, please let me know the exact issue you are facing and if possible the URL to your website on your host. **EDIT** : The issue that OP was facing was `unable to connect to database`. So the solution was to update DB details in the `wp-config.php` file.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "database, mysql, directory, localhost, phpmyadmin" }
Visiting posts results in 404 errors after host migration I have migrated my WordPress blog from one host to another by way of transferring the files and exporting/importing my database, updating URL references where needed. On my new host, I can successfully view the front-page of my blog however visiting posts results in "404 - Page not found" errors, seemingly regardless of my permalink settings. My blog as it resides on the new host can be found at www.erogol.com Any one know the reason?
All your inner links use the `wwww` subdomain instead of the `www` subdomain. Check your General Settings to see if you added an extra `w` in your site url. For example: This fails: < This succeeds: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "permalinks, url rewriting, 404 error, options, migration" }
Filter archive.php by custom meta I"m trying to filter an archive page by custom meta query. I've tried using `query_posts($args)` prior to the loop, but it returns nothing. Any ideas? Here's what I have so far: <?php //$wolfName = $_GET['wolfName']; $archiveArgs = array( 'meta_key' => 'wolf', 'meta_value' => 'boltz' ); query_posts($archiveArgs); ?> <?php if (have_posts()) : ?> It returns no posts... any ideas?
Use `pre_get_posts` action hook function archive_meta_query( $query ) { if ( $query->is_archive){ $query->query_vars["meta_key"] = 'wolf'; $query->query_vars["meta_value"] = 'boltz'; } } add_action( 'pre_get_posts', 'archive_meta_query', 1 );
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "custom field, query posts, archives" }
What is the best way to store custom variables I need to store the id and secret key of my FB application. I don't want to write them directly in my template. What do you recommend ?
I recommend you to store it in WordPress options table using function add_option() function as this is site specific data and not post/category specific.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "variables" }
I want empty search returns to home page in my wordpress I want empty search returns to home page in my wordpress . how i can do this . im trying to using javascript and html tags , but te are not too fast . if no result user returns to home page not to nothing found page.
This will do exactly what you're asking for: add_action('wp', 'redirect_empty_search'); function redirect_empty_search() { global $wp_query; if( isset( $_REQUEST['s'] ) && 0 === $wp_query->post_count ) { wp_redirect( home_url() ); exit; } } You'll want to add some kind of message on the homepage when this happens, maybe by adding a query parameter to home_url() and displaying a message in your theme when that parameter is set. Something like: wp_redirect( add_query_arg( 'searchfailed', '1', home_url() ) );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "search" }
Use date in the URL of custom post type So I've created a custom post type, say `reviews`, and its archive is available at `<domain>/reviews/`. I want to categorize them by date. So every day (or week) I publish a `reviews` type post and I want its url to be `<domain>/reviews/2013/09/05/<post-name>`, so that users will be able to list all the `reviews` from specific year, month or day. Just like we have a similar feature for the regular posts. All the plugins I've tried are old and aren't working with WP 3.6. So is there any solution (maybe even built-in)? Or at least some direction so I can code it myself? I would appreciate any help.
Custom post types can not use the "day/name" permalink structure defined in WordPress permalinks settings. You need to add your own rewrite rules to fit your needs. For example: add_action('init','my_rewrite_rules'); function my_rewrite_rules(){ // Replace custom_post_type_slug with the slug of your custom post type add_rewrite_rule( 'custom_post_type_slug/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+)/?$', 'index.php?custom_post_type_slug='.$matches[4], 'top' ); } Note that I've not tested the code above. You need to flush the rewrite rules before you test it.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, rewrite rules" }
Make Custom Taxonomy Category Use Parent Template I have a Wordpress custom post type set up in my `functions.php` called "Research" I have a custom taxonomy called "Classifications" Under that taxonomy I have the terms/categories: Old Research (parent) --- sub cat 1 --- sub cat 2 I have created the file "taxonomy-Classifications-oldresearch.php" which successfully changes the parent layout for me. However, it does not hold the layout in the sub categories. The sub-category pages revert to another file `taxonomy-Classifications.php` I can alter it by also creating `taxonomy-Classifications-subcat1-oldresearch.php` but I will have a lot of sub categories that I want to use ONE template for - the parent cat template. This way I don't have to create a new template file for every new category.
Hook into `template_include` filter add_filter('template_include', 'research_term_template'); function research_term_template( $template ) { if ( is_tax('classifications') ) { $parent = get_term_by('slug', 'oldresearch', 'classifications'); // to improve performance you can hardcoding 'oldresearch' term id // $parent = 12; if ( term_is_ancestor_of( $parent, get_queried_object(), 'classifications' ) ) return get_template_directory() . '/taxonomy-Classifications-oldresearch.php'; } return $template; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "custom taxonomy, templates" }
How to turn this .htaccess rule into a dynamic rule with add_rewrite_rule, et al? In .htaccess, I have this: RewriteRule ^land/(.*) /?land=1&exper=$1 [QSA,L] which makes sth like this: domain.com/land/exper1 fill in the $_GET with $_GET['land'] = 1 and $_GET['exper'] = exper1 Great. I want to take this out of .htaccess and add the rule dynamically, that is, look for other querystring values like 'ocean' instead of 'land'. I want the values to be filled into $_GET or some other var where I can evaluate them. I cant figure out if add_rewrite_rule is sposed to actually overwrite my .htaccess, but all the things i've tried, flush_rewrite_rules(true), etc arent doing it.
Try this and follow the same structure to add more rewrite rules or query vars: add_filter('query_vars', 'my_query_vars'); function my_query_vars( $vars) { $vars[] = "land"; $vars[] = "expert"; return $vars; } // Add the new rewrite rule to existings ones add_action('init','my_rewrite_rules'); function my_rewrite_rules() { add_rewrite_rule( 'land/(.+)/?$' , 'index.php?land=1&expert=$matches[1]' , 'top' ); } Don't forget to flush the rewrite rules by going to the admin area->Settings->permalinks->click save.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "htaccess, rewrite rules" }
custom post creation on front page - on submit a search is done Using a child theme of WP 2013 theme... In Settings > Reading, 'Front page displays' I have selected 'static page' and assigned it a page titled Home. For that page, I've assigned a custom template. That template calls a custom shortcode that displays a form for creating a custom post. And a loop to show the 10 most recent post of that cpt. Everything works fine - except that on submit, it refreshes to the archive page for the category assigned when creating the custom post. So it searches for that category. If I call the same shortcode on a different page, such as Contact, that isn't a front page, then on submit it will refresh to that page. Why does it search for the category when submitted from the front page? And how can I stop it?
add `the_permalink();` in form action value, to submit the form data. <form id="fep-new-dog" name="new_dog" method="post" action="<?php the_permalink(); ?>">
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, pages, homepage" }
How do I block a subdirectory from WordPress theming? I have a WordPress site. It works great. But I have a subdirectory on my server where I work on client websites. It's a development space and most of those sites are NOT WordPress. Sometimes (but not all the time?) my site's WordPress theme will takeover a page and mess up all my styles. I don't care so much about WHY this is happening... but how do I prevent it? I assume I need to edit my .htaccess with some extra line of code. Alright, here's a page that's being corrupted by WP styles: * See my current WP site at fowlertown.com * Here's a non-WP page on a new site I'm building: < * Here's how that page SHOULD look: < Notice the header and footer; the middle section is broken right now anyway.
Turns out my trouble was caused by a stray server-side include that was returning a 404, which WordPress tried to intercept. `This is not the WordPress problem you are looking for.`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "themes, htaccess, directory, css" }
Where is get_header('shop') file in Woocommerce templates I need to modify the **get_header('shop')** file in Woocommerce but don't know where it's located, if someone knows please help me out - thanks!
`get_header( $name )` is a Wordpress function, that will try to load the file `header-{$name}.php` from your theme's root folder. If this file doesn't exist, Wordpress will load the default `header.php` file.
stackexchange-wordpress
{ "answer_score": 14, "question_score": 6, "tags": "templates, plugins, headers" }
add_action which contains first argument admin_print_scripts-$page Here I am not getting whats the meaning passing `$page` with admin_print_scripts ? My code is like : $page = add_submenu_page('edit.php?post_type=' . $post_type, __('text', 'plugin-dir-name'), __('text', 'plugin-dir-name'), 'edit_posts', 'text_' . $post_type, array(&$this, 'text_list_admin')); add_action( "admin_print_scripts-$page", array(&$this, 'text_scripts')); I have read < < but whats the difference between them? **Update** I want to add those script on Here when am giving `$page='shop_order_page_member_list';` it applies on all member_list page but I want to apply on specif page so I tried `$page='shop_order_page_member_list_type_order_cal';` but its not working
< echos inline javascript in all admin pages header but < echos inline javascript in specific admin page header passed as second parameter.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "actions" }
WooCommerce plugin appearance and look Is it possible to customize WooCommerce plugin the same as my own theme? Im about to finish the theme development, and I was wondering if it's possible to style the WooCommerce Checkout system that it looks the same as the theme Im creating? Thanks
It certainly is possible - take a look at the woocommerce documentation: < < You can find the information you need there.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins" }
Insert posting automatically based in acf field good day I found a code that works, but it creates several posts of the same name, do not want that, he wanted to create only once post_type if the value is 'x', but he is creating a 'x' every time updates , how do I create it only once this post_type? **My Code** : <?php wp_insert_post( array( 'post_status' => 'publish', 'post_type' => 'fornecedores', // post_type which is created posting 'post_title' => get_field('fornecedor'), // Custom field to generate the post type 'post_content' => '' ) ) ?> Code is in a loop of the post type products. Understand me?
Before inserting check if post exists: $exists = get_page_by_title( get_field('fornecedor'), OBJECT, 'fornecedores'); if ( empty( $exists ) ) { wp_insert_post( array( 'post_status' => 'publish', 'post_type' => 'fornecedores', // post_type which is created posting 'post_title' => get_field('fornecedor'), // Custom field to generate the post type 'post_content' => '' ) }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, wp insert post" }
How can recognize post's category? I want my plugin to recognize post's categories before post is loaded. i wrote this code but it works in category page not in post's page with the category is specified from me. function checkUser() { if(is_category('programming')){//it doesn't work when post with "programming" category is being displayed echo "Bingo!"; include_once ('TEMPLATEPATH/get-messages.php'); exit(); } } add_action('template_redirect', 'checkUser');
`is_single()` is intend to work with post types, not categories. To check for category you should use `is_category('programming')`. Note that `is_category` works on category archives, not on single view. So, if you want to check in the current is a single view and has the category 'programming' you need the `has_term` tag: if( is_single() && has_term('programming', 'category', get_queried_object()) ) { include_once ('TEMPLATEPATH/get-messages.php'); exit(); } See is_single, is_category and has_term on Codex. Also have a look on how conditional tags works in WP.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, categories, page template, template redirect" }
where to set the PO file for a plugin? I have a Cimy user plugin and I want to make translations and then force the Cimy user to read from my translation. Should I define the language in `wp-config.php` in the root folder? I do not know where to change it? I have `define('WPLANG', 'fa_IR');` in `wp-config.php` and it is reading from path > \wp-content\languages Should I change the fa_IR PO edit and just add the ones from Cimy user in the bottom of the WordPress fa_IR PO? or I should use separate file?
First of all, the plugin should support translation. If it is so, the directory where to put po/mo file is defined by plugin, usually they are in a directory `/langs` or `/languages` in plugin directory. That directory is (should be) defined by plugin using load_plugin_textdomain The plugin you are using has a subfolder `cimy-user-extra-fields/langs` where you can find the existing localization files. **Your files (`cimy_uef-fa_IR.po` / `cimy_uef-fa_IR.mo`), should be putted in the same folder.** To create these files you can use the software PO Edit a powerful software, maybe not very easy to use. If you already don't know it I suggest you the plugin Codestyling Localization a powerfull well written WP plugin that will help you trought the entire process of transalitng plugins, themes and wordpress itself.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "translation" }
Link to previous month's posts On my homepage I am showing only the current month's posts. I'd like to include a link to the previous month's posts at the bottom of the page. Wordpress has `get_month_link` (< I can use this function like so to get the month number, minus 1 = previous month: $archive_year = get_the_time('Y'); $archive_month = get_the_time('m'); $previous_month = $archive_month - 1 <a href="<?php echo get_month_link( $archive_year, $previous_month ); ?>">Last month's posts</a> This will output a link like "/?m=201308" if the month is September. In most cases this will work, but when I get to January, the `$previous_month` var will be "01 - 1", and won't give me "12" for December's posts. Any ideas how to make this a little more fail-safe for situations like December? Many thanks
$archive_month = date('m', strtotime('1 month ago') ); $archive_year = date('Y', strtotime('1 month ago') ); echo '<a href="' . get_month_link( $archive_year, $archive_month) . '">Last month\'s posts</a>';
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "pagination, navigation" }
What is the difference between using global $current_screen and get_current_screen()? I have been looking at `get_current_screen();`. I have seen there is also a global `$current_screen;` that I could use. Here are two examples: // Using function function wpse_post_notice() { $screen = get_current_screen(); // Only run in post/page creation and edit screens if ( $screen->post_type === 'post' ) { return 'This is a post'; } } // Using gloabl function wpse_post_notice() { global $current_screen; // Only run in post/page creation and edit screens if ( $current_screen->post_type === 'post' ) { return 'This is a post'; } } Is one method considered better than the other? If so why?
In your example, there is currently no difference. You get the same object, if there is one. Try it: global $current_screen; $current_screen->foo = 1; $screen = get_current_screen(); $screen->foo = 2; echo '$current_screen->foo: ' . $current_screen->foo; // 2! The simple reason: objects are not passed as a copy in PHP. **But:** global variables are really bad, because everyone can change them any time. One day far, far away, WordPress might deprecate this global variable. If you are using the function wrapper to get the object, you should be fine. Otherwise, your code might raise notices. And always check if you get indeed an object. `$current_screen->post_type` might not exist.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "plugin development, globals" }
display link to a custom plugin in admin menu bar i have a custom plugin and i want the link to the plugin be accessible in the **admin menu bar** of the `wp-admin` right now, im using below code. but the link to this shows under my settings. what hook should i replace with the `add_option_page`? function custom_plugin() { add_options_page("my plugin", "plugin settings", 1, "my plugin", "custom_function"); } add_action ('admin_menu', 'custom_plugin');
if you want to add a top level menu page then you need to use `add_menu_page()` function more details on codex add_action( 'admin_menu', 'register_my_custom_menu_page' ); function register_my_custom_menu_page(){ add_menu_page( 'my plugin', 'plugin settings', 'manage_options', 'my-plugin-settings', 'my_plugin_custom_function', plugins_url( 'myplugin/images/icon.png' ), 66 ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
What's the best way to detect referrer? I've been searching for some WP specific way to detect any referrer. Have an idea? I know how to do that in PHP but I just want to know if there's some WP function to do that? **EDIT:** here is what I 'm trying to test => $referer = wp_get_referer(); if ( strpos($referer ,' !== false ) echo 'you come from wordpress.org';
The best way to check the referrer will depends of what are you trying to do. You can use wp_get_referer() or wp_get_original_referer(), but if you want to check the referer for security reasons you should definitely use other functions like check_admin_referer(), check_ajax_referer(), wp_referer_field() or other of the Wordpress Nonces related functions.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "http api" }
Custom filtering on month value only of an entire date field I'm using the plugin Ajax WP Query Search Filter (< to search some custom posts I've created. The filter works great on three custom taxonomies, however I also want to include a filter on a date field where the full date is stored. The filter I'd like is a dropdown containing each month, as such: * Jan * Feb * Mar * Apr * May * ... etc... This would search the date field on its month value. My question is how do I do this? * dd/mm/yyyy I know I can create a Custom Meta Field filter, but how I would get it to search on the month part only? Thanks, Chris.
I've solved it by creating a Custom Meta Field filter using the following options: -01-::Jan|-02::Feb|-03-::Mar|-04-::Apr|-05-::May|-06-::Jun|-07-::Jul|-08-::Aug|-09-::Sep|-10-::Oct|-11-::Nov|-12-::Dec The "-mm-" in each part matches the month stored in the database. Pretty simple really but this works perfectly.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom taxonomy, ajax" }
Update field in database for users I have made a frontend form for the admins where they can check a checkbox for each user and submit the form data by post. For all the users that are checked, a value should be changed in a field in the database. The slug for this field could be `payment_status`. What is a method to update or change the value of a field in the database for **a specific user**? I have looked at a question like this: Update some database fields when post is saved And have been trying with the options methods in wordpress. But I have trouble finding the way to change the value for the specific user. When this is possible for me, it might not be difficult to convert this into repeating the update process for every checked user in the post data.
Have you seen the `update_user_meta()` WordPress function?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, database, options" }
What is the use case for the "Class" parameter in register_sidebar? I registered a new sidebar and filled in the `class` parameter (see code), I then dropped in an Archive widget and went hunting for my "testing" class. **Not there**. So what is the class parameter used for. Can I see an example? register_sidebar( array( 'name' => __('Footer Widget One', 'wpbs-framework'), 'id' => 'footer-01', 'class' => 'testing', 'description' => __('The first footer area', 'wpbs-framework'), 'before_widget' => '<div class="footer-sidebar-widget">', 'after_widget' => '</div> <!-- end footer-sidebar-widget -->', 'before_title' => '<h4>', 'after_title' => '</h4>' ) );
If you fill class parameter to register_sidebar function then the class sidebar-{class name} gets added to the div of that sidebar in the back end. For example if you register the sidebar using following code : register_sidebar( array( 'name' => __('Footer Widget One', 'wpbs-framework'), 'id' => 'footer-01', 'class' => 'testing', 'description' => __('The first footer area', 'wpbs-framework'), 'before_widget' => '<div class="footer-sidebar-widget">', 'after_widget' => '</div> <!-- end footer-sidebar-widget -->', 'before_title' => '<h4>', 'after_title' => '</h4>' ) ); then in back end you will see the sidebar div having class 'sidebar-testing' as following <div class="widgets-holder-wrap sidebar-testing">
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "widgets, register sidebar" }
Best Way to Add UnEditable HTML to Posts I find myself more and more needing to use tables or divs inside my wordpress posts content. The problem I find with this is that one wrong backspace or newline, copy / paste has the possibility to throw off the whole code. Is there a best practices when it comes to adding html inside the content? Is there a way to make it so that the user cannot delete certain things inside posts content? For Example: On one of my websites I have an accordion. Each accordion content is seperated by `div class="accordContent"` but when the user adds a new line inside the current `accordContent` div, it ends the current div and creates a new one with the same class that throws off the code.
> Is there a way to make it so that the user cannot delete certain things inside posts content? You need... 1. A shortcode that will generate the content. This will let your users provide input but the markup can be rigidly controlled. 2. Or a custom meta field. The markup around this can also be rigidly controlled, but to a lesser extent, or in a different way. 3. Or you need to write the markup into the templates. I can't tell you exactly which you need. I'm not sure. I think the shortcode, or a group of shortcodes, might do what you need.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, html, content, customization" }
Avoid to load default WP styles in login screen Is there some way to avoid the load of default WordPress styles in login screen to only load my custom stylesheets? Actually I'm using this code: function login_styles() { // Sets the styles if is the current theme if (get_stylesheet_directory() == get_template_directory()) { // Prints link to stylesheed login.css wp_register_style(...); wp_enqueue_style(...); } } add_action( 'login_enqueue_scripts', 'login_styles' ); It works well but WordPress first loads its styles. I want to exclude that files from this screen.
Using `wp_deregister_style( 'login' )` to remove the login styles will still result in a 404'd request for the login CSS file. However, if you re-register the login style after deregistering it you can prevent the unwanted request. add_action( 'login_init', function() { wp_deregister_style( 'login' ); wp_register_style( 'login' ); } ); This will leave you with a completely unstyled `wp-login.php` page. To restyle it you could instead register your own CSS file under the `login` handle. This might be more helpful than messing with the `style_loader_tag` filter. * * * **Update:** `login_enqueue_scripts` is a more appropriate action and dequeuing doesn't result in a 404. add_action( 'login_enqueue_scripts', function() { wp_dequeue_style( 'login' ); } );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "login, css, wp enqueue style, wp login form, wp register style" }
Is it possible to add a superscript trademark symbol to a menu? Is it possible to add a superscript trademark symbol to a WordPress menu?
You should be able to use any HTML entities for the titles. I've put `&trade;` in menus before. You can also try the code: `&#8482;`
stackexchange-wordpress
{ "answer_score": 3, "question_score": -1, "tags": "menus" }
why the wp_register_script doesn't work for register_activation_hook I want to register a script when my plugin is activated. So I wrote: register_activation_hook(__FILE__, 'register_script'); function register_script(){ wp_register_script('addjs',' } Next, I created a meta box and enqueued the script in the `add_meta_boxes` hook: wp_enqueue_script('addjs'); But that doesn't work. Why? My js file is just a simple alert function. However, when I register my script using init hook or other hook, my code works - why?
Whatever is hooked to activation runs in just a single request when the plugin is activated in a sandbox, and the output is captured to check for errors. Your code won't run on any subsequent request after that single activation, so your script will not be registered. It works on init because that action runs on every request.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, plugin development, wp enqueue script" }
wpdb_prepare with multiple or condition I want to execute a query like this: $wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )..., $string ); If I do the query with only one condition it works: $wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' )..., $string ); What is the error in my first query?
I think your first partial code be this partial code: $wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )..., $string, $string ); You have to have to pass the same number of arguments into the query as you specify (with %s) in it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "database, mysql, sql, wpdb" }
Query to get last posts from authors of blog Firstly I get user with role "author". $author_args = array( 'role' => 'author' ); $authors_list = get_users($author_args); Nextly I reform array $author_list = array(); foreach((array)$authors_list as $author) $author_list[] = $author->user_nicename; And then finally query args $author_posts_args = array( 'author_name' => $author_list, 'post_type' => 'post', 'cat' => $colecti_id, 'posts_per_page' => '4', ); $author_posts_query = new WP_Query($author_posts_args); Why it doesn't works?
get author ids instead of author nicename to get posts for muliiple authors using WP_Query(); $author_list = array(); foreach((array)$authors_list as $author) $author_list[] = $author->ID; // make comma separated string from author ids array $author_list = implode(',', $author_list) and change wp query args $author_posts_args = array( 'author' => $author_list, 'post_type' => 'post', 'cat' => $colecti_id, 'posts_per_page' => '4', ); $author_posts_query = new WP_Query($author_posts_args);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, users" }
How to set default status to custom post type When I save my custom post_type 'product', I'd like to set their status to my custom status 'incomplete'.
Hook `wp_insert_post_data` filter to force a post status to be set as incomplete before it can be set as published. With the following code only a post that is set as incomplete can be saved: add_filter( 'wp_insert_post_data', 'prevent_post_change', 20, 2 ); function prevent_post_change( $data, $postarr ) { if ( ! isset($postarr['ID']) || ! $postarr['ID'] ) return $data; if ( $postarr['post_type'] !== 'product' ) return $data; // only for products $old = get_post($postarr['ID']); // the post before update if ( $old->post_status !== 'incomplete' && $old->post_status !== 'trash' && // without this post restoring from trash fail $data['post_status'] === 'publish' ) { // set post to incomplete before being published $data['post_status'] = 'incomplete'; } return $data; }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "custom post types, post status" }
How can I debug what is wrong ? Featured images stopped showing not sure when this happened, but my featured images are now not showing. Instead I see "NO THUMB" Any ideas how I can find the cause ? So far I have disabled and reenabled all plugins, to no avail. Thanks in advance EDIT : The images exist on the server in several sizes. WP_DEBUG is currently set to false. UPDATE : After checking the error_log file, it appears that the first critical error is this : [09-Sep-2013 13:48:02] WordPress database error Table './myhosting_mydb/wp_postmeta' is marked as crashed and should be repaired for query SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (1520) made by require('wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, update_post_caches, update_postmeta_cache, update_meta_cache Not sure what to do with this, however....
I JUST had a similar error in fact. You need to fix your db first. Go into your mysql admin and do a repair on that table, then things should be ok. If you have phpmyadmin, do this: 1. Sign into phpMyAdmin 2. Click on your database name on the left 3. click on SQL in the tabs on the top 4. In the query box enter: "repair table wp_postmeta" and then click Go. Hope this helps, it worked for me a couple of days ago.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails, media library" }
mass delete posts based on metadata I need to delete all posts that have a certain meta value for a certain meta key. I am looking for how to do this directly in the DB. So for instance, I have a meta field called "state", and I want to delete all posts (and there are thousands) whose meta value for that key is NOT equal to "CA". I have found queries that delete all posts of a certain type and all associated meta data, but can't find one that will let me delete posts BY metadata.
from my comment above: I can do this now with two separate queries, but it would be nice to be able to do it in one. Still, this is progress. The first query is like this: `DELETE wp FROM wp_posts wp LEFT JOIN wp_postmeta pm ON pm.post_id = wp.ID WHERE pm.meta_key = 'state' AND pm.meta_value != 'CA';` And the second (to clean up the orphan metadata) is like this: `DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post meta, sql" }
Get menu names and same depth level menu names Let's say I have a menu like this.. Home Food -- rice -- apple -- sushi Sports -- soccer -- basketball -- football Color -- red -- blue -- black When I am on sushi page, I need to get like this.. (like breadcrumb) Food > sushi Current menu name and upper level menu name (if there is) And when I put mouse on sushi, it will be a dropdown menu showing same depth level menus "rice, apple, sushi" I may be able to working on the dropdown script but I don't know how to get these menu names and links. Please let me know if you have any idea.
Sorry, this is a little vague but it should get you started. It seems like you need to: 1. Check if the page has a parent `<?php if($post->post_parent) ?>` 2. Something like `<?php echo $post->post_parent; ?>` 3. Something like `<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>` 4. Something like the code below, then apply your solution for turning it into a dropdown. There is more info here: < <?php $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "breadcrumb" }
How to achieve anchor links on top of pages. I have been looking around for a plugin or a how-to but I been unable to find the answer. I am trying to get a box with anchor links at the top of my pages. I can see and example on the official wordpress site. See the right hand side that says 'Contents' and 'Related'. < Does anyone know the best way to achieve something like this? Thank you
If you're trying to do this **just** for anchor links within your current WP page, a table of contents style plugin will likely suffice; for example, see: < This specific example auto-generates the table of contents and anchors based on the headers in your document/page, so it is fairly low fuss on you as the end user.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages, links" }
Link to Authors blog posts I am trying to create a link in my template that allows the user to see there own blog posts the code that i am using is `<li><a href="?author=<?php the_author_ID(); ?>">test</a></li>` but it is only taking me to `?author=`
`the_author_ID()` says in Codex: > It displays the unique numeric user ID for **the author of a post** ; the ID is assigned by WordPress when a user account is created. This tag must be used **within The Loop**. So, it won't work. Try using the following code* within a loop: <li class="author vcard"> <a class="url fn n" href="<?php echo get_author_posts_url( false, $authordata->ID, $authordata->user_nicename ); ?>" title="<?php printf( __( 'View all posts by %s', 'my-theme' ), $authordata->display_name ); ?>"><?php the_author(); ?></a> </li> * _Thanks toIan Stewart_
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "users, author, blog" }
Cannot display default template after switching to custom I'm having a strange issue with a page. The site has a Default Template (page.php) and several custom templates. A page was created using a custom template (page-services.php), but then later switched to use the Default Template (all via Admin Page Attributes). However, the page's front end continues to pull the custom template instead of the selected Defaul Template. The back end is correct (there are different custom fields depending on the template). The edit page view shows the correct custom fields for the template selected. I can't think of any other details that might be relevant.
Refer to the Template Hierarchy to help understand what's going on here. When you create a custom page template, it is identified as such by the header within the file, not by filename. But you've also named the file following the `page-{slug}.php` format, and as you can see in the Template Hierarchy, WordPress looks for the template named `page-services.php` for a page with slug `services`, if no custom template is assigned. In your case, they're the same file. Rename your custom page template file so it doesn't clash with other template naming formats and this problem will disappear.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "page template" }
Storing state between hook functions I have two functions which I'm hooking into a plugin. Both functions are called (at different times) during a single page creation by the server. I want to set a flag in function_a which can be read by function_b. **Question: Is there any problem with just declaring my flag in the global scope? Is there a preferred WP-style for doing this?** ps. I realize that I will need to be defensive when function_b reads the flag--by making sure that the value was explicitly set, etc.
Uing OOP for your plugin it's very easy. class MyPlugin { static $flag; static function function_a() { self::$flag = 'a value'; } static function function_b() { if ( ! is_null(self::$flag) ) echo self::$flag; // echo 'A Value'; } } add_action('plugins_loaded', array('MyPlugin', 'function_a') ); add_action('init', array('MyPlugin', 'function_b') ); Not using OOP you can use `global` variables. function function_a() { global $myflag; $myflag = 'a value'; } function function_b() { global $myflag; if ( ! is_null($myflag) ) echo $myflag; // echo 'A Value'; } add_action('plugins_loaded', 'function_a' ); add_action('init', 'function_b' ); This works and seems easier, but first solution is better for sure.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "hooks, variables" }
Adding pages to the Admin panel Instead of going to Pages on the Admin panel nav bar on the left to see all the pages that are created. I would Like the pages to show up on the Admin panel nav bar it self. Like a custom post type. How can I do this. Any help would be greatful.
If I get you correctly, you are trying to add a new menu to the Admin Panel. For that, the following tutorial would be one of the best for you to such: > * **The Complete Guide To The WordPress Settings API** (Part I - VIII) > The key things are: * `add_menu_page()` * `add_submenu_page()` * `add_theme_page()` \- for theme options * `add_plugins_page()` \- for plugin
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "customization, admin, page template" }
Use Advance Custom Fields to fill text widget I have a custom WYSIWYG field setup in Advance Custom Fields Plugin and I want to show that content in a text widget on the sidebar / widgets. I've tired the shortcode and the php code but no luck.
Text widgets don't allow PHP code, see the codex. You can use a plugin (see here) So putting `<?php echo get_field('name_of_your_field'); ?>` in the text area of your widget will not work, putting it in a page template should work. If you put it inside the loop you should use `<?php echo get_field('name_of_your_field'); ?>` and if you put it outside the loop you can get the field of a specific post ID by passing it through the get_fields function like this: `<?php echo get_field('name_of_your_field', 1234); ?>`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "advanced custom fields" }
Videos in posts are not rendered I have a wordpress website, but the blog/post side of things wont display videos even when using the insert media/video link. It just shows the code up. What page/file do I need to edit and where to get this to work?
Add this line where you want to display the video: <iframe width="604" height="453" src=" frameborder="0" allowfullscreen></iframe> replacing "your_video_id" with your id (find it in your youtube account).
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "videos" }
How to display sql query fired by posts_where I have used add_filter( 'posts_where', array(&$this, 'new_filter_where' )); function edcal_new_filter_where($where = '') { global $wpdb; $where .= " AND (($wpdb->postmeta.meta_key = 'assignto' AND $wpdb->postmeta.meta_value = '7')) "; return where; } now how to print sql query that fired by my filter?
The quick and dirty way is to put `var_dump($wp_query->request)` (or whatever you've named the `WP_Query` object if you've created a new one) on the page the query runs on and after it runs. You can also add `define('SAVEQUERIES', true);` to `wp-config.php` to save the queries for analysis. You can read the queries something like this from the Codex: if (current_user_can('administrator')){ global $wpdb; echo "<pre>"; print_r($wpdb->queries); echo "</pre>"; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post meta" }
Can I have a link within a WP UI Spoiler I'm using the WP UI plugin, and have a page set up with spoiler shortcodes so that you can "click to show" and "click to hide". Here's a link to the page in question: < My problem is this: I want to include a hyperlink within the text of one of the spoilers (which you only see after you "click to show"). When I inserted the html at wordpress "Edit Page", it displayed the actual html, instead of showing as a link. Here's my spoiler: `[wpspoiler name="Do I need to buy travel insurance?" style="ui-lightness"]GoInspire highly recommends buying travel insurance for non-refundable tickets and land costs. Speak to our agent at 845-425-8255 ext. 209 for more info, or click <a href=" target="_blank">here</a> to read about our plans.[/wpspoiler]` Is there a way past this?
I was able to make your spoiler code work on my site. The `<`, `>`, and `"` characters in your spoiler code are encoded on your site, breaking the link. I think that either your theme or one of your plugins is encoding those characters. To test your theme, temporarily switch to one of the default themes (such as Twenty Twelve) and see if that fixes the problem. If not, deactivate your plugins and see if that fixes the problem. If it does, reactivate your plugins, one at a time, until the problem comes back.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, links" }
Add / Remove Post Type from "Link to existing content" popup I would like to be able to remove a custom post type AND add attached media (PDF's, Images, Docs, etc) to the "Link to existing content" in the Add / Edit link popup in the WYSIWYG editor. Essentially, I've created a custom content type, but have way to many with the same name. So, I'd like those removed from the search results. In addition, I have a bunch of PDF's I've uploaded and would like to easily be able to link to those. Anyone ever accomplished this, know a plugin or have the hook to modify it?
Old question but I found an answer at Here by Simon Hampel at the bottom. Cool filter, but I coulnd't find a whole lot of documentation on it so I'm not 100% sure everything it's connected to. One thing I do know is it's used to pull the links on 'Link to existing content'. Put this in your `functions.php` file: function custom_wp_link_query_args($query) { $pt_new = array(); $exclude_types = array('exclude_post_types_here'); foreach ($query['post_type'] as $pt) { if (in_array($pt, $exclude_types)) continue; $pt_new[] = $pt; } $query['post_type'] = $pt_new; return $query; } add_filter('wp_link_query_args', 'custom_wp_link_query_args');
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "custom post types, links, wysiwyg" }
Custom permalink with two parameters I am using custom structure for permalink: `/%postname%/%page%/%year%/`. When I navigate to ` it gives me 404 "Page not found". Nonetheless, it is working fine with ` (without year) and `get_query_var('page');` is returning `19`. Now, I just need the value of `get_query_var('year')` instead of getting weird 404.. Here is what the .htaccess file looks like: AddHandler php-stable .php # 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 Is there any limit for number of parameters that can be set in custom permalinks? Any suggestions, what might be going wrong?
As I suspected, I had to finally gave up on pretty link and changed the permalink back to: > /%postname%/%page% Then I changed the URLs to ` in shortcode, I passed $_GET['fyear'] and with the ugly query string it just works.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "permalinks" }
Shortcode are not working in Option tree textarea I am using option tree. In textarea, i place shortcode [layerslider id="1"] its not working, i also found same post replied by plugin author allow shortcodes in textarea in option tree applied the do_shortcode('[layerslider]'); still no solution
Got the solution. you can use shortcode _e.g._ **[layerslider id="1"]** in textarea/textbox and call it by the **name** to the textarea/textbox use in option tree function files _e.g._ get_option_tree( 'textboxname');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "shortcode, theme options" }
Building theme so user can change header image My Google-Fu is letting me down so I'm trying it here. I'm building a theme and I want the customer to be able to change the header image him/herself in the wp-admin. How do I go about this? As I said my Google-Fu has been embarrasingly lacking on this one so even a link to where to start would be fantastic. Thanks!
1. You can add theme support in your functions file for a Custom Header page using this code which also enables you to add a default size and selector class which you can style with CSS. add_theme_support( 'custom-header', array( 'width' => 320, 'height' => 60, 'header-selector' => '.site-title a', 'header-text' => false ) ); 2. Or this method enables the user to change the header image in every page. You can add this feature using custom fields with a header hook which isn't difficult. The hardest part would be coding the meta box to display on all edit screens however the Codex offers a very basic example. Another solution would be to use the code from the Twenty Eleven default theme which enables the use of Featured Images as header images on every single post or page. Slick featured for a theme in my opinion as it already includes the meta box.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "loop, images, headers" }
What is difference between logout and switch off? What is the difference between logout and switch off in wordpress 3.6 except below? 1.Logut - redirect to login screen of admin. 2.Switchoff - redirect to UI side.
You have the plugin User Switching installed From their FAQ: > ## What does "Switch off" mean? > > Switching off logs you out of your account but retains your user ID in an authentication cookie so you can switch straight back without having to log in again manually. It's akin to switching to no user, and being able to switch back. > > The Switch Off link can be found in your profile menu in the WordPress toolbar. Once you've switched off you'll see a Switch back link in the footer of your site. ## From my experience: The plugin allows you to switch to another user's profile and see what that user sees without knowing their login credentials. After you're done, you click on switch off to go back to using your profile.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "logout" }
Unwanted Links and Spam Wordpress Pages and Posts In webmaster tools I have a number of crawling errors of the Google spider. for example < They say they cannot crawl to this page.. but what kind of page is this ? what is /de there ? I checked the link and my site says the page doesn't exist. Then i just noticed that my "Akismet" is not activated... So i will activate it now and how can i remove that extra link in my site?
I forgot to activate Akismet. :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, permalinks, urls, security, spam" }
Create un-removeable user How can I add a Wordpress user that can't be deleted (at all cost, not even by a superadmin) with some code? I can't find anything on Google about such a _god-account_. This morning a client of our company deleted the main-admin account and deleted all of the websites content. We were able to restore the website with a backup, but i would like to prevent this problem in the future.
While you can't guarantee the absolute safety of this user, I have used this to _hide_ my backdoor user (useful for clients who are aggressive in removing users, yet may forget to pay their bill, for example) add_action('pre_user_query','sleeper_pre_user_query'); function sleeper_pre_user_query($user_search) { global $current_user; $username = $current_user->user_login; if ($username != 'my_secret_admin_user') { global $wpdb; $user_search->query_where = str_replace( 'WHERE 1=1', "WHERE 1=1 AND {$wpdb->users}.user_login != 'my_secret_admin_user'",$user_search->query_where ); } } I'd name the function something mundane sounding, might want your user to be mundane as well. The code prevents any other user from seeing that user in the admin list.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "admin, user roles, account" }
List child pages of a specific page I'm looking for a snippit/function that will list the child pages of a specific page (I guess by page ID) but not necessarily when you are on that page or a child of that page. The parent page (Parents Area) and its child pages are listed below: Parents Area - Term Dates - Calendar - School Blog - Letters to Parents - Attendance I want to be able to be on any page of the website, specifically within single posts and post archives but be able to list out just the children of the parent page "Parents Area".
To list subpages of a particular page, use `wp_list_pages` with `child_of` argument. $parent_page_id = 42; wp_list_pages( array( 'child_of' => $parent_page_id ) );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "navigation, child pages" }
Delete user after Contact Form 7 submission I need to allow users to delete their accounts on the front end, but need to collect some information about their reason for leaving. I'm using Contact Form 7 to collect the info, and want to use a hook to delete the user. When I use the function below, I receive an email with the info from the form, but it doesn't delete the user. function outta_here() { global $current_user; $delete_me = get_currentuserinfo(); wp_delete_user($delete_me->ID); } add_action( 'wpcf7_before_send_mail', 'outta_here' );
You're doing it wrong. get_currentuserinfo() returns the data into some preset global variables. Try this: function outta_here() { global $user_ID; get_currentuserinfo(); wp_delete_user($user_ID); } add_action( 'wpcf7_before_send_mail', 'outta_here' ); You can read more about get_currentuserinfo() on WP Codex.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "users, plugin contact form 7" }
WordPress emails translate to French My client's site is in French and we want to translate the canned emails (such as user registration and password lost) to French. What are the hooks/filters for these? The default language is french, i.e. define('WPLANG', 'fr_FR');
He just need to get French Version of WordPress
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "localization" }
Line of Tag information Is Formatted Strange I'm placing a tag list in the post footers on a blog. You can go to this specific post: < and scroll down to the post footer see what the tags looks like currently: "filmsvideoTags:," is what it looks like to me. I would like it to look like "Tags: films, videos" Here's my code: <?php the_tags('Tags:', ', ', '<br/>'); ?> which is according to the codex here: < I've tried all different kinds of things trying to figure out what the problem is...with no solution found yet. Help?
It's because of some CSS that you have. This is what causes your problem, the float:left utility a { height: 30px; line-height: 30px; display: inline-block; float: left; letter-spacing: 0; } Add the code that generates your tags in a div with "float: none"
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "tags" }
Can Wordpress used as a CMS? I saw many people use WordPress as a CMS, is that common? but the problem I noticed is that the download in such sites is slow, is WordPress slow?
Wordpress IS a CMS. It hasn't been just a blogging platform for a long time. And no, it's not slow if you don't make it slow. WP out of the box is really fast, but people slow it down with poorly-written plugins and themes. You can do whatever you want with Wordpress, as it has hooks for basically everything. And you can find a lot of information in the Codex. There are also tons of tutorials online.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "cms" }
Check for files and database integrity Someone started an automatic update of the WP core via dashboard today, and as it was taking too long, decided to cancel it. How do I check the files and the database for integrity to detect a possible corruption?
From development point of view the most practical way to detect and locate changes is version control - comparing against SVN/Git checkout of core or use such checkout directly. However there are also plugins around that verify files against set of hashes. I think Sucuri Security recently got such feature. The practical limitation of them is for which versions hashes are provided and how fast are they updated for new releases. For database there isn't quite any easy method (not counting native MySQL functionality). On other hand WP doesn't do _much_ to database on updates nowadays and it comes as separate explicit action (via splash screen) after file update was performed. From you description process probably hadn't reached that point and no changes to database were attempted.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "updates, automatic updates" }
Missing HTML comment tags I've this WP installation that I'm currently modifying. And the craziest thing is that the HTML comments are not displayed anywhere in the source. That is if you right click on the page and "View Source". However if you are to open the page with a tool like this -> < you can clearly see that the comments are there. The website url is < The sad part is that there is no info anywhere on the matter and as a bonus I've no idea on how to determine if this is caused by the code itself, the Apache, WordPress or whatever... (By the way, I've 5 other sites on this server, 4 of which are running WordPress and none of them has this problem. I'm also running an offline version of w3lol that does't show the problem either.) Have anyone had an error like this? And do you have any suggestions on how to fix it?
It seems that my ISP's DNS was not refreshing and was caching some stuff. While waiting for them to fix it as a temporary solution I changed my DNS to Google's public DNS as shown on this page developers.google.com/speed/public-dns/docs/using and everything seems fine.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "html" }
Is priming a Transient Cache possible? I'm currently using Wordpress Transient Caching when querying images I've uploaded and tagged. Using Transient Caching has really sped up these queries once they are cached, but unfortunately, once the cached query expires it is only cached again when someone loads that page. Is it possible to preload/prime transient caches so users don't get stuck with that responsibility and long wait time? If not, should I be using something else to cache that does have that ability? Thank you in advance for any advice
Your issue is not as much priming (which only happens first time) but that cache refreshes in solution you are using are synchronous. Transients API is not dealing with updates by itself, it is handled by code that calls it. So it doesn't implement async updates. On other hand there is nothing that prevents implementing async on top of it. It can be done in custom code or making use of generic solution with such functionality, for example WP-TLC-Transients library.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "transient, cache" }
Limit the_excerpt in the first point (.) of the sentence I would like to filter the function `the_excerpt` to stop to find the first endpoint. Ex: "This is the article summary which ends at the endpoint with a full-stop." Any idea is welcome.
First, please make sure you understand the difference between `the_excerpt` and `the_content`. You are asking about `the_excerpt` but I suspect that you might actually mean `the_content`. That said... You can filter the `the_excerpt` function with a filter of the same name. add_filter( 'the_excerpt', function ($excerpt) { return substr($excerpt,0,strpos($excerpt,'.')+1); } );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "excerpt, limit" }
Remove submenu item from list I have the following script within my `functions.php` file to avoid certain users from modifying things they shouldn't and would like to remove one more item, the _Appearances > Themes_ submenu. function remove_menus () { global $menu; $restricted = array(__('Dashboard'), __('Posts'), __('Pages'), __('Comments'), __('Plugins'), __('Users'), __('Tools'), __('Links'), __('Settings')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} } } add_action('admin_menu', 'remove_menus'); How would I be able to achieve this?
Use the API functions `remove_menu_page` and `remove_submenu_page` to remove menu items rather than manipulating global variables. This will remove the themes page under appearance: function wpa_remove_themes_submenu() { remove_submenu_page( 'themes.php', 'themes.php' ); } add_action( 'admin_menu', 'wpa_remove_themes_submenu', 999 );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, functions, menus, admin menu, sub menu" }
How to filter multiple queries with search? My theme has two columns, each column has it's own query. When I do a search on my theme, it only filters the main query and not my secondary query that is on my second column. How do I do that?
> When I do a search on my theme, it only filters the main query... It's exactly how it should do. The url change only the main query (or better, the main query in the one fired by args in the url). If you have secondary query on same page, they continue to work using the args that you pass to `WP_Query`. So if you want secondary query also use the `s` param, pass it as argument. $args = array( // ... you have your query args here ... ); // next line check the main query for the 's' argument and if present add it to args if ( get_query_var('s') ) $args['s'] = get_query_var('s'); $secondary_query = new WP_Query( $args ); // your loop here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query" }
Post/Custom Post Type URL Access Is there a way to prevent people from visiting a post's permalink? A lot of times we create posts or custom post types that end up being included as part of the content of a page or some other feature and are not always intended to be viewed individually. A good example might be for a slideshow. You create a few posts where each individual post is the content of a slide in the slideshow. Each one of those posts has a unique permalink, something like `example.com/slide-one`. There's no reason for someone to be able to access that individual post so I would like to "hide" it.
If you don't expose the permalinks on the front end, then there's no way for someone to reach them, but if you want to absolutely prevent it then set `publicly_queryable` to false when you register your post type.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, posts, urls, user access" }
Category.php loads first before page.php? I've got a problem with the following: I made a category called app-functions, when viewing my domain.com/app-functions/ it opens up the category-app-functions.php instead of page-app-functions.php. Does anyone know why this happens? Also.. with the view of SEO, page.php is more important then category.php.. right?
WordPress select template, following its Template Hierarchy logic. What you have that is category archive, templates for individual pages are never considered for it. > Also.. with the view of SEO, page.php is more important then category.php.. right? PHP template file is entirely back-end concepts, it doesn't have anything to do with SEO inherently.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "categories, pages, seo" }
List of a specific Custom Post Type in Custom Template My WP 3.6 has created a custom template using `register_post_type()` named `movie`. I inserted few `movie` via `Admin Dashboard > Movie`. For Permalink, I have set to Post Type, therefore, for example, `movie1` (instance of Custom Post Type `movie`), the URL is: > < If I want to show a list of `movie` with link ` which custom template file has to be created? I already have `single.php`, `single-movie.php` for displaying the `movie1`. But how about a list of `movie` ?
Firstly, there is the `archive-POST_TYPE.php` file, so in your case it would be `archive-movie.php`. You find more information on that (and all the other templates) in the Template Hierarchy. Secondly, you can just list your custom posts anywhere you want, using a separate query: $args = array( 'post_type' => 'movie', // maybe put some other settings here as well ); $movies = new WP_Query($args); if ($movies->have_posts()) { while ($movies->have_posts()) { $movies->the_post(); // now work with `the_content`, `the_title` and the like... } } wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, templates" }
Show terms in archive page I am trying to show terms of specific post type on archive page. I don't understand how to "echo" term name. Here is my code: <?php $terms = get_terms("event_cat"); ?> <?php while (have_posts()) : the_post(); ?> print term->name here <?php endwhile; ?>
`get_terms()` retrieves terms in general, it makes no connection to a current post in loop. What you need is one of template tags, which retrieve terms for the post. For example `the_terms()`: while (have_posts()) : the_post(); the_terms( get_the_ID(), 'event_cat' ); endwhile; There are quite a few functions dealing with terms, depending on what you want to do with data.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, terms" }
How to display value of custom fields in page I have a custom post type called 'software', contained within are various custom fields such as subtitle, price, screenshots, download link, etc. I created a function to allow use of the tinyMCE edit window for some of these custom fields. I have been trying to display these fields on the page but with no success. The method I'm using is this: <h1><?php the_title();?></h1> <h3><?php echo get_post_meta(get_the_ID(), 'subtitle', TRUE); ?></h3> Here is a link to the page. Below the `<hr/>` on the page is a list of all the meta created. The ONLY one of the fields which will display is 'price' for some strange reason. Anyone have any idea what I'm missing?
Well, you are using: get_post_meta(get_the_ID(), 'subtitle', TRUE); So, you are saying to Wordpress to get the meta value of the 'subtitle' field and that the returned value be in format of string. See get_post_meta() docu. To get all meta data of a post you should use get_post_custom() function instead. For example, if you are inside the loop: $custom = get_post_custom(); foreach($custom as $key => $value) { echo $key.': '.$value.'<br />'; } This will return all meta data of the post. If you want to check, for example, the "price" meta field: if(isset($custom['price'])) { echo 'Price: '.$custom['price'][0]; }
stackexchange-wordpress
{ "answer_score": 30, "question_score": 27, "tags": "custom post types, custom field, theme development" }
Is there anyway to rewrite woocommerce-template.php? I am trying to do some customizations on the woocommerce-template.php file but I fear it will be overwrite on the next update. I wonder if there is a way to rewrite a function from functions.php with another one loading my custom file. This is the function present within woocommerce: public function include_template_functions() { include_once( 'woocommerce-template.php' ); } I wonder if there is a way to overwrite it or anyother way to do so.
All of the functions in that file are pluggable functions, you can define any of those functions in your theme's `functions.php` file or another plugin and they will override the WooCommerce core functions. There are also a number of filters in most of those functions which may allow you to do what you want without having to override the entire function.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
Insert custom div between posts I'm using twenty twelve and I need to insert a div between the posts. I'm not sure how to stop the loop, insert the div, and then restart the loop. Can anyone shed some light on this? Thanks.
You can check your position within the loop using the `current_post` var of the `$wp_query` object, and insert markup at a specific spot or at some interval. A simple example: while( have_posts() ): the_post(); the_title(); the_excerpt(); // if current_post is 1, insert the div // note that current_post starts at 0, // so this will be after the second post's content if( 1 == $wp_query->current_post ): echo '<div>My div!</div>'; endif; endwhile;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, query posts" }
ThickBox width can't be changed in admin I'm trying to make pop up in admin area (in post edit screen) and i can't make my thickbox wider then 670px (width: 670px). Here's my thickbox code that shows thickbox: tb_show( ed.getLang('m7.popup_title'), '#TB_inline?width=800&height=600&inlineId=mygallery-form' ); (it works after clicking the tinyMCE button) and i get div with id="TB_window" <div id="TB_window" style="width: 670px; height: 216px; margin-left: -335px; top: 48px; margin-top: 0px; visibility: visible;"> (code is from google browser) So if i manualy change width and then resize browser it gives 670px back to width.. Can it be somehow changed so that thickbox show all the content wich is 800px wide ? it creates insede #TB_window div with id="TB_ajaxContent" wich is 800px wide
From the comment under my question ( may be someone could miss it, so posting it as an answer )[PS: slightly modifyed it]: I think i found a solution how to change the width, but that's not the real solution.. I still don't get it why thickbox width is 670px (as u can see in my code (will follow next) the global thickbox width is set like the passed arg!! ) So the solution was: function m7_resize_thickbox(){ jQuery(document).find('#TB_window').width(TB_WIDTH).height(TB_HEIGHT).css('margi‌​n-left', - TB_WIDTH / 2); } jQuery( document ).on( 'ready', function() { tb_show( ed.getLang('m7.popup_title'), '#TB_inline?width=800&height=600&inlineId=mygallery-form' ); m7_resize_thickbox(); // after tb_show we need to update width/height values; we could also do something like jQuery( window ).trigger( 'resize' ); } jQuery(window).on( 'resize', m7_resize_thickbox );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "thickbox" }
wp_insert_comment and security **I am using wp_insert_comment to offer an in-house better ajax conditional comments interface. i got it all working great. my only question is.** What security measures should i take to make sure i leave security holes? the comments are submitted via ajax and so in the php file reciveing the data i use $_POST to collect data. How would you treat those inputs so make it bullet proof as possible and **I know how to secure forms so i am basicly asking:** Does wp_insert_comment run (After submission) trough any other built in wordpress functions?
`wp_insert_comment()` is low level function, it only saves passed data without concern for what it contains. If you are looking to replicate sanitizing WP does on comment data (totally good idea :) you are probably looking for higher level `wp_new_comment()`.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "comments, ajax, security" }
How do I get the current edit page ID in the admin? Most solutions I found are for front-end use. This is for a plugin, so the all activity is in the back-end. How do I get the page ID that's being currently use(edited) in the admin? **Note** I'm out of the loop. I just need to get the ID of page(not posts) that I'm currently seeing in the back-end.
You can also use $post_id = $_GET['post']; Or you can use a hook (probably better). function id_WPSE_114111() { global $post; $id = $post->ID; // do something } add_action( 'admin_notices', 'id_WPSE_114111' ); You will need to add a conditional since this will run on all admin pages, I recommend using `get_current_screen();` For example to run only on _pages_ : function id_WPSE_114111() { global $my_admin_page; $screen = get_current_screen(); if ( is_admin() && ($screen->id == 'page') ) { global $post; $id = $post->ID; var_dump($id); } } add_action( 'admin_notices', 'id_WPSE_114111' );
stackexchange-wordpress
{ "answer_score": 27, "question_score": 14, "tags": "functions, admin, id" }
Get one custom taxonomy category I am trying to do something which I thought would be simple but I am at a loss. (I've googled, played with different code, etc.) I have the following Custom Taxonomy `Job Attributes`. I have two check box category terms(?): * paid * union 1. I would like to display a taxonomy link for 'union' if union is selected. 2. I would like to display a taxonomy link for 'union' if union AND paid is selected. In other words, I would like to ignore that 'paid' is selected. Breakdown: 1. paid selected = display nothing. 2. union selected = display taxonomy link 'union'. 3. paid AND union are selected = display taxonomy link 'union'. I am also trying to make this into a short code; I am integrating into something else: function wpv_check_for_union_func() { // Ive tried a bunch of thing and would appreciate some leads. } add_shortcode( 'wpv_check_for_union', 'wpv_check_for_union_func' );
Your logic looks to me like it boils down to "if `union` is selected, then echo a link to `union`, else do nothing." I think your description is much too complicated. It looks like you can effectively ignore `paid` completely. function wpv_check_for_union_func($attr,$content='') { global $post; $taxonomy = 'yourtaxslug'; $union = has_term('union', $taxonomy, $post); if ($union) { $term_link = get_term_link( 'union', $taxonomy ); if( !is_wp_error( $term_link ) ) { return '<a href="' . $term_link . '">union</a>'; } } } add_shortcode( 'wpv_check_for_union', 'wpv_check_for_union_func' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy" }
Which template holds what to display when search returns nothing Question is clear I guess. Normally, which template is returned when no search results are found. I would say search.php, but my parent theme's (twenty thirteen) search.php looks like this (slightly edited): <?php if ( have_posts() ) : ?> <header class="page-header"> <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentythirteen' ), get_search_query() ); ?></h1> </header> <?php /* The loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php twentythirteen_paging_nav(); ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> So, what is the `none` after `content` in the third last line? What exactly is fetched from `content.php` then?
`get_template_part( 'content', 'none' );` will look for: 1. `content-none.php` 2. `content.php` Twenty Thirteen does have `content-none.php`. In general this is organized in such way to support dynamic lookups where first two-part template might or might not exist and fallback to more generic template, if necessary.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "search, content" }
Wordpress Customise I'm looking for a plugin that lets me put a "please wait" message (similar to **notebook-driver.com** where you're redirected to download link after a few seconds) when people click on certain links. For example, when people want to download something off my blog, I redirect them to a page with advertisements that is displayed for 5 seconds before the download is initiated. Does such a plugin exist? or how to do this manually ? Thanks.....
The interstitial page on that website isn't part of Wordpress. It's just an external page with some ads and a download link on it. You can easily do this by yourself. Create a php file named download.php on your server and add the following code to it: <html> <head> <meta http-equiv="refresh" content="5; url=<?php $_GET['url'];?>" /></head> </head> When you link to this page for the download link to work, do it like this: < You can add whatever else you want to download.php, of course.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, plugin development, customization, links, optimization" }
How to track who has deleted files This is really strange, last night my wordpress has everything in woocommerce store and today all of sudden, the pictures and attributes are gone. How can i see or check wordpress log (if any) what actions took place in last 24 hours. I do use File Montior plus, but its giving me 504 error and not running efficiently.This is really critical!
WordPress does not log anything natively. Closest it has to such functionality are just post revisions and ability to enable logging of PHP errors. There are plugins around to log events, but since you hadn't one installed in advance it won't help you retroactively. If you think it was from action by logged in user you might get some information from web server's HTTP logs, since they should capture requests to WP admin pages.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, phpmyadmin" }
Data won't save if metabox within conditional in admin. What am I missing? What is wrong with this setup? Metaboxes inside this conditional will not get saved. // Only shows for the admin front-page assigned page. $front_page_id = get_option( 'page_on_front' ); $post_id = (empty($_GET['post'])) ? NULL : $_GET['post']; if (is_admin() && $front_page_id == $post_id) { ........ } _Background:_ The idea of this setup is to have only on the static front page(Settings -> Reading) meta fields for the user to upload images that will be use on the slider.
You have to use `$_REQUEST` instead of `$_GET`, because when an user saves a post the `POST` request will be send to the server. It means that there is no `$_GET['post']` argument and your meta boxes won't be registered. And if they are not registered, then nothing will be saved. // Only shows for the admin front-page assigned page. $front_page_id = get_option( 'page_on_front' ); $post_id = (empty($_REQUEST['post'])) ? NULL : $_REQUEST['post']; if (is_admin() && $front_page_id == $post_id) { ........ }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "customization, admin, metabox" }
use of nickname and nicename? nicename is used for author slug in url. But can anyone tell what is the especial use/application of 'nickname' user meta field in wordpress ? or it is just another extra field to show nickname.
`nickname` field is one of the options made available for choice in "Display name publicly as" option in user profile. It has no other use in core code, as far as I know.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "username" }
Undefined WP_Query::has_posts()? This must be wrong. I was testing something so I did: $queried_post = new WP_Query(array('posts_per_page' => 5, 'offset'=> 1, 'category' => 1)); var_dump($queried_post->has_posts()); exit; And I get the error: Fatal error: Call to undefined method WP_Query::has_posts() I am working with this inside a class INSIDE the theme .... `var_dump($queried_posts);` shows 5-6 posts. even if their were no posts I would get false. I should get .... true ....
It isn't `has_posts`, it is `have_posts`. You've just got the method name wrong. That's all. <
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "wp query, loop, query" }
adding custom classes for tables I have to implement a default class for HTML-Tables at WordPress. The wp-standard is `<table>` .. ist there any way to do this, that i get this output per default? `<table class="abc xyz">` maybe with filters?
In your case you need to add custom hook for `the_content` filter: add_filter( 'the_content', 'wpse8170_add_custom_table_class' ); function wpse8170_add_custom_table_class( $content ) { return str_replace( '<table>', '<table class="mycustom-class">', $content ); } Add this snippet to your `functions.php` file.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "functions, customization" }
Loading WP core Thickbox through frontend Looking through some of the top Google results, this question has been answered a number of times, but the answers given don't seem to be working in my WP 3.6 install. One solution given is this: function my_thickbox() { if (!is_admin()) { wp_enqueue_script('thickbox', null, array('jquery'), true); wp_enqueue_style('thickbox.css', includes_url('/js/thickbox/thickbox.css'), null, '1.0'); } } add_action('init', 'my_thickbox'); Another was this: `add_action( 'wp_enqueue_scripts', 'add_thickbox' )`. I've also tried using this `add_thickbox()` with no success. All of these approaches seem to successfully load `thickbox.css`, but no JS file is showing up. I can manually go and include the path to `thickbox.js`, but that seems less desirable given that all of this seems to be handled by the core in `script-loader.php`.
You need to add a call of `wp_footer();` function. Do it before closing body tag in your `footer.php` file. It should look like this: <?php wp_footer(); ?> </body> </html>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "core, thickbox" }
Remove query string except from google map api I have an issue similar to many others in the web, but still with no solution so far. To remove query strings i've used the following code: function _remove_script_version( $src ){ $parts = explode( '?', $src ); return $parts[0]; } add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); add_filter( 'style_loader_src', '_remove_script_version', 15, 1 ); What i'ld like, is to know if someone believe to know how to set up a code to exclude googple map api query string from being removed. To fix the error below: > “The Google Maps API server rejected your request. The “sensor” parameter specified in the request must be set to either “true” or “false”. Does anyone beleive to know how to fix this?
First of all I would like to strongly recommend you to not remove query parts of javascript and stylesheet files. Why? Because they contain a version of a file. Why do I need it for? We need to add version to each file (whenever it is possible) to prevent versions collisions. These collisions could appear when a new version of WP/plugin is released and you update it from admin panel. In this case, your users' browser won't be notified that a new version of a script exists and won't download it, but will use previous one which is stored in browser cache. But if you strongly confident that you don't need it and still want to trim query strings, you can do it by changing your function to the following view: function _remove_script_version( $src ){ return add_query_arg( 'ver', false, $src ); } add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query string" }
Custom Stylesheet instead of Inline CSS for Wordpress Customizer API Overrides I've looked at Wordpress Customizer API and it looks to be able to achieve what I'm looking for; allowing the developer to set aside as many dynamic styles which can later be configured by the Wordpress admin. However, the recommended mechanism for injecting the styles is really not cool. All guides I've read online and from Wordpress recommend they be added inline to the Head of the document. With the popularity of such documents flooding the net I was unable to find a definitive guide on how to add these codes neatly to a stylesheet! Can get theme mod() be called from a PHP stylesheet? Sorry please bear with me as I'm just weeks into PHP and Wordpress documentation. Any suggestions would be nice I'm sure there are many developers who would not accept inline CSS.
> However, the recommended mechanism for injecting the styles is really not cool. All guides I've read online and from Wordpress recommend they be added inline to the Head of the document. That's how HTML works, no fault of WP's. Dynamic stylesheets have always been a challenge since CSS is not dynamic language by nature. There is number of options, which all can be implemented relatively neatly in WordPress, however all have drawbacks. 1. Inline styles. Bloat page source size, but just work. 2. PHP script serving CSS. Highly flexible, but serving extra PHP script is orders of magnitude slower than serving static CSS file. 3. Compiling and serving static CSS files. Somewhat challenging to implement (especially in code for public use), but has least performance drawbacks. Overall the way to go depends much more on your performance requirements and how will final product be used, than specific option. There is no winning one here.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, theme customizer" }
boostrap on wp-admin backend via plugin installation how can i add and use the twitter bootstrap to my wp-admin backend by a plugin installation approach? i plan to create multiple custom plugins and i just want to add bootstrap as a global style instead of using it per plugin this is my code, it doesnt seem to work. <?php /* * Plugin Name: bootstrap * Plugin URI: * Description: add boostrap * Author: some guy * Author URI: * Version: 0.1.0 */ function theme_name_scripts() { wp_enqueue_style( 'style-name', get_stylesheet_uri() . '/custom/css/bootstrap.css'); } add_action( 'wp_enqueue_scripts', 'theme_name_scripts' ); ?>
For use in the admin, you need the admin_enqueue_scripts hook instead of wp_enqueue_scripts.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "twitter bootstrap" }
What is the difference between user_description and description? In the codex page for `the_author_meta`, the list of fields available for the function lists both `user_description` and `description`. What is the difference between the two?
The `user_description` field is alias of `description` field. Nothing more. If you echo both of them on one page, you will see that they are identical and shows the same information about user's bio.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "author" }
How to implement filesystem cache in Wordpress I'm currently using the Transients API to cache some product details from Amazon. Now I'm looking into adding a file system cache. But I have no idea how to implement it. The only thing that I can think of is to actually save the JSON string representation of a specific product into a text file. Is this worth it? Are there any proven performance benefits when doing this or does it have the same performance to that of the database? Thanks in advance.
Some of caching APIs in WordPress, including transients, can make use of swappable Object Cache backend. There are ready-made implementations around for it which use file system as storage engine. However determining if it's worth it is another matter entirely. In _usual_ case database is very likely to outperform disk for typical caching tasks. However there are combinations of factors out there that _might_ make disk preferable (when data gets prohibitively large for individual database entries, etc). Unless you can practically benchmark and determine limitations of your current setup it's unlikely that you need dedicated file cache. PS note that more commonly Object Cache backends use memory caches (APC, Memcache, Redis) and that unsurprisingly tends to outperforms database and disk either for caching tasks
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development, cache, filesystem" }
Put CSS on TOP, how? I have this mission, that regards setting my existing CSS on HEAD. I've tried to make a search on if there was any kind of plugin or code to automatically set the CSS code directly in Head. The main purpose is to follow YSlow recomendations such as "Put CSS on Top" How can i do that? Is there a code for it? a plugin? Does someone believes that can help me with this? My domain is <
Would be interesting to see if you get the same YSlow message when checking your site without any plugins. Its a little difficult to be sure because of the minification of HTML/CSS on your site, but it seems some of the plugins are not inserting stylesheets in to the `<head>` part of your document, and placing them when they appear instead. From my understanding of YSlow's documentation < it helps to ensure progressive loading - or in other words, the visual loading of the site for the end user is enhanced. If a fresh install of your theme (perhaps on a test site) results in the same YSlow message, then feel free to ignore the above. If not, perhaps activate each plugin and run the test to see which ones are adding them in erroneously - then maybe drop the plugin authors an email.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -2, "tags": "css, headers" }
WordPress loads whole jQuery UI library My wordpress loads whole jQuery UI library <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' <script type='text/javascript' src=' Is this normal? I didn't noticed the same behavior earlier.
jQuery-UI is _included_ in every default WP installation. Whether it is _loaded_ depends on your theme and/or plugin(s). Three Options: * live with it * disable plugins one by one (and switch theme), figure out which is responsible and whether that's needed * manually deregister it (something, i.e. a plugin, will probably break)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "javascript, jquery, jquery ui" }
Contact Form 7 filter similar to preprocess_comment Does the Contact Form 7 plugin have a filter similar to WordPress's preprocess_comment? I'll be using this filter to check the body of the message for certain words and call wp_die() to display a message and prevent further processing of the message.
I think **wpcf7_before_send_mail** is what you're looking for. You can find some examples of it in action in this unofficial documentation and in this support thread where the plugin developer gives some guidance on using it..
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "filters, plugin contact form 7" }
Variable not staying set This is most likely just a PHP problem, and it's probably a pretty simple answer, but I just can't seem to get my brain to function this morning. This is what I'm trying to do: $job_file = $cfs->get('job_file'); // job_file is a URL if ($job_file = NULL) { echo "NOT AVAILABLE"; } else { echo '<a href="'. $job_file . '">' . get_the_title() . '</a>'; } It will display the URL of the current page instead of the `$job_file` variable. What am I missing?
Well, this **is** PHP... if ($job_file == NULL) { ... You might want to compare, and not set, right?
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php, variables" }
Missing items on page I'm missing items on my web page and I think it is due to some jQuery problems. But I'm not sure and I am unable to find the bug. On this site, on the upper-right corner there is a shopping bag 'widget', and on my site there is none but the white space indicates that it's trying to be there. Now I made a gist of the differences of both sites (< but still cant find a bug maybe a more experienced WordPress developer sees it in a second. I have tried disabling all the plugins, flushing the cache and ask for theme support on GetBowTiedSupport - Ticksy, but there's no response from the developer so I hope to fix it through this channel.
it was because of the theme was dump. i had installed WooCommerce already but it didnt understand that because the theme also wants to install WooCommerco. So i had to deinstall WooCommerce and let the theme install a really old version of WooCommerce and then upgrade to the current version of WooCommerce.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, jquery, front end" }
Customize wp-admin form custom fields I would like to customize some form elements in my WP admin area: starting from this example (< the one with the select) what I would liko to do, is to update a via a select field. In order to do so I started including this function: function my_enqueue() { wp_enqueue_script( 'my_custom_script', get_template_directory_uri() . '/js/admin.js' ); } add_action( 'admin_enqueue_scripts', 'my_enqueue' ); Inside "admin.js" I placed: alert("It works!"); And it does work. But whenever I try to include anything related to jQuery nothing happens: the code is being included inside the page and I get no errors in Firebug. For example a script as simple as the one you can find at < $("input").keyup(function(){ $("input").css("background-color","pink"); }); Doesn't work. Nothing happens. So I wonder, what am i missing or doing wrong? Thansk a lot!
I am not sure this is your problem if you are not getting any errors, but make sure you have your jQuery code within document ready wrappers and pass the $ in to make sure you can access it since Wordpress runs in no-conflict mode. jQuery(document).ready(function($) { $("input").keyup(function(){ $("input").css("background-color","pink"); }); }); It would also be good to declare jQuery as a dependency just to be safe. wp_enqueue_script( 'my_custom_script', get_template_directory_uri() . '/js/admin.js', array( 'jquery' ) );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery, wp admin, forms" }