New answers tagged

1

get_next_posts_link() and get_previous_posts_link() are for linking between pages of a paginated post archive. For navigation between individual posts you want get_next_post_link() and get_previous_post_link(). Note the singular "post". function myslug_render_post_navigation(){ echo get_next_post_link( __( 'Previous post' ) ) . ' | ' . ...


0

I've managed to print the error message by adding the following to the functions.php: function exception_handler($exception) { echo "Uncaught exception: " , $exception->getMessage(), "\n"; } set_exception_handler('exception_handler'); For some reason logs did not include the error details before. The error is call to undefined ...


0

Your code is fine to me, except you made a mistake here: template_redirect('/product/channel-mcgilchrist'); WordPress does not have a function named template_redirect, only a hook with that name. So you should have used either wp_redirect() or wp_safe_redirect() which are valid functions to perform URL/page redirections in WordPress. wp_safe_redirect( '/...


0

You can check the current user role in the same action and apply "display none" for that specific user role $user = wp_get_current_user(); if ( in_array( 'author', (array) $user->roles ) ) { //The user has the "author" role }


0

You have to think into the opposite direction: Don't pull the variables from the template, push them into it. Templates should be as simple as possible, the shouldn't know anything about the content of the rest of your code, for example function names. In other words: use hooks. In your template: // the numbers are just context examples do_action( 'something'...


2

You can't replace the function, but you can substitute it: Copy the function to your child theme's functions file. Rename the function. Modify it as needed. Find the template file that references it, such as header.php, and copy that to your child theme. In your child theme's new template file replace the reference to the original function with your renamed ...


0

You need to get the term object first. //Your meta field $post_custom_title = get_post_meta($post_id,'car_name',true); //Get the term object by id. change taxonomy_slug to the taxonomy you intend to use $term = get_term_by( 'id', $post_custom_title, 'taxonomy_slug' ); //Retrive the term name and use it as post title $term_name = $term->name; //call the ...


-1

Hey so it is possible to do this, I wrote an article about it. You need to do it on the javascript side using the Gutenberg's data module api. Here's the code that'll get this up and running for you. /** main.js **/ import BlockRestrictor from './BlockRestrictor' /* * Add a mapping of block names and what templates they are * restricted to. */ const ...


0

Within the wp_get_document_title() function we have: // If it's a search, use a dynamic search results title. } elseif ( is_search() ) { /* translators: %s: search phrase */ $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); so you could hook into the ...


0

From what we have to go on, it sounds as though your locations will become WooCommerce product categories (or tags). You can also create new categories if you're already using WooCommerce's default category.


0

You absolutely did not understand how the code from my previous answer works, yeah? The PHP ternary operator $result = $a ? $b : $c works the same way as the following construction: if ( $a ) { $result = $b; } else { $result = $c; } So the whole idea was to check if the get_user_meta(get_current_user_id(), 'last_name', true) function returns an ...


1

Try the tag_cloud_sort hook: add_filter( 'tag_cloud_sort', 'shuffle_tags', 10, 2 ); function shuffle_tags( $tags, $args ) { shuffle( $tags ); return $tags; }


0

The first thing that i am not getting is $exclusive->y ? can you please share custom field settings that you have created? And the second thing that i have found, you must have to put global $post; in the first line of the function : add_filter( 'the_title', 'wpb_new_title', 10, 2 ); function wpb_new_title( $title, $id ) { global $post; if('post' == ...


0

Use PHP ternary comparsion operator to check if get_user_meta() function returns blank or non-blank result: function colaborador_nome($atts) { if (is_user_logged_in() && !is_feed()) { return '&nbsp;'. (get_user_meta( get_current_user_id(), 'first_name', true ) ?: "Hi >No Name<, please settle your name in your account.")...


0

The issue here is that both the functions have the same name - colaborator_avatar(). Make sure that $new_user contains the current user. Else use get_current_user_id() like this: get_user_meta( get_current_user_id(), 'first_name', true ); Show avatar and first name: // show user avatar if logged in function colaborator_avatar($atts) { if (...


0

I searched for 'wordpress get name of logged in user' and the first result gave wp_get_current_user, which will show logged in user first name. Examples of how to use from that page: $current_user = wp_get_current_user(); /* * @example Safe usage: $current_user = wp_get_current_user(); * if ( ! ( $current_user instanceof WP_User ) ) { * return; * } ...


1

I fixed the issue myself by editing a line in functions.php and it no longer shows the error message for me. The error was: Warning: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ (this will throw an Error in a future version of PHP) in /var/www/web33/web/wp-content/themes/slanted-master/functions.php on line 73 So on line 73 in functions.php ...


0

The code exactly as you put it in your question works fine for me and does exactly what you suggested. To make it work I had to make sure my WP post editor was in code editor mode as HTML or Visual Editor may create extra problems: And this is what my test code in the post editor looked like, when I had a successful test: <!-- wp:html --> <p>...


-1

Do you mean something like this? function some_function( $a ) { return $a * 2; } function my_shortcode( $atts ) { $params = shortcode_atts( array( 'value' => 0 ), $atts ); return (string)some_function( $params['value'] ); } add_shortcode( 'my-shortcode', 'my_shortcode' ); When you use [my-shortcode value=2] on your page, it would ...


1

Not sure what you would need this for but this is how you take the data of the variable $result from the operation function to your shortcode: operation(); function operation(){ $result=5+1; return $result; } function my_function(){ $result = operation(); return (string)$result; } add_shortcode( 'my-shortcode', 'my_function' );


0

You can do this like bellow // register shortcode add_shortcode('last-modified', 'last_mofied_shortcode_callback'); function last_mofied_shortcode_callback() { $output = '<ol class="list-numbered">'; $recently_updated_posts = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => '13', '...


0

Do not use "about" as handle as it seems to be not unique and used by WordPress itself. I don't see the list of style handles is documented somewhere. Anyway, use something unique like 'rejaur-about': <?php function load_page_styles() { if ( is_front_page() ) { // enqueue front page styles } elseif ( is_page('about') ) { ...


0

it's shoud be working - example : 1 - index page view 2 - index sourse 3 - target page - no custom template for it 4 - target page sourse 5 - functions.php


0

Update Your condition to is_page_template( 'about.php' ) for details visit WP Official documentation https://developer.wordpress.org/reference/functions/is_page/ https://developer.wordpress.org/reference/functions/is_page_template/#comment-497


0

I don't really understand what you're trying to do. Why don't you just call the function inside the shortcode handler? This looks more like general PHP question. Say we have a variable in our functions.php or wherever you define your shortcodes: $another_var = doSomeFunctionThatReturnsData(); With modern anonymous functions, you can pass variables using the ...


1

This will depend on how your theme is structuring the templates for single.php (individual post view) but I'll show you what to look for and how to apply via CSS. So from a theme I'm working on, this is where the category gets included in the post: <article id="post-3417" class="post-3417 post type-post status-publish format-standard hentry ...


0

This may be a terrible way to go about population of a CF7 field... However, the way I have done so in the past is to use an identifier as the default value of the field you want to populate, for example {{cf7_year}}. I would then use a mixture of PHP to query and get the values (if required), and format that result into a string that can in-turn be used in ...


0

I dont understand where are you calling from. I can give you an alternative solution that may or may not work in your case (since I don't fully understand your case): This is your ajax-url on your site: echo admin_url( 'admin-ajax.php' ); Usually we attach it to the JS to run AJAX calls: wp_localize_script( 'THE_JS_THAT WAS_ENQUEUED', 'PARAMS', array( '...


2

That's not how filters work. Much like a filter in real life, something goes in, it gets changed, and the result goes out. Filters always take in a parameter and return something. They're an opportunity to change something So if we take this: $review_num_fetch = apply_filters('tourmaster_review_num_fetch', 5); This means the plugin uses 5, but it has given ...


1

As of WordPress 5.4 _doing_it_wrong() is no longer marked private, so it looks like we can just use it.


1

Few possibilities here: In index.php you find the_content() and replace it with: $content = get_the_content( $more_link_text, $strip_teaser ); $content = apply_filters( 'the_content', $content ); $content = str_replace( ']]>', ']]&gt;', $content ); $replace = array( 'autoplay=""' => '' ); $text = str_replace(array_keys($replace), $...


0

In general programming, globals are bad practice: You can't easily look at the use of a global in one place and see all the other uses, e.g. where it was set or will be read later. You have many places to change the use of that variable if e.g. the use or format of it changes. This makes it hard to make reliable changes to your code and to debug where/who ...


-1

Well if u already use your variable in the global scope, you should also define it in the global scope, not inside the function. You can then simply include the php file where u define ur global variable (lets call it source script) into the script u wanna use, with a simple include or require statement before using it. I precisely work like this too in my ...


0

It looks like wp_list_categories($args) will output directly when you call it, which is why the output comes out in a weird place. and ideally what you need is to capture the output and return it, but luckily wp_list_categories allows you to do this with the 'echo' parameter. Try: $args['echo'] = FALSE; return wp_list_categories($args); Note the extra '...


0

You have forgot to save custom meta field data so check it below code I have done it. Reference add_filter( 'woocommerce_checkout_fields' , 'occasion_checkout_field_update_order_meta' ); function occasion_checkout_field_update_order_meta( $fields ) { $fields['billing']['occasion'] = array( 'type' => 'select', 'id' => 'occasion', '...


0

I had the need to add a download CTA after the content of all case studies of a website, but "in exchange" of user's data for: display a CF7 form on your page, I had the same one on all case studies post type single which I hooked after the content find a way to get the wanted PDF url for people to download, as for me all case studies have a ...


0

Yes, this absolutely is possible. There are a couple of steps that you would need to take to get this working; Check that the user is currently on the front page, you can use the is_front_page function for this, you may need to use is_home or even both depending on your configuration and requirements. Check that the user is currently logged in, you can use ...


0

What do you consider to be the home page? Do you want to change what is answering on the / url on your website? If so, I think that you can use the init hook and use wp_redirect() function to send your user wherever you want based on the result of wp_get_current_user() result. Something like that. add_action('init', function () { if ($user = ...


1

// You can retrieve your link and get the id (contact ID=4 for example) $link = $_SERVER['HTTP_REFERER']; $page_id = url_to_postid($link); if (page_id == '4'){ $subject = "This subject line is for the Contact page."; } else { $subject = "This subject line is for every other page."; }


0

I solved the issue with help from this answer: https://wordpress.stackexchange.com/a/159570/176615 // add nofollow to Amazon function add_nofollow_content($content) { $content = preg_replace_callback( '/<a[^>]*href=["|\']([^"|\']*)["|\'][^>]*>([^<]*)<\/a>/i', function($m) { if (strpos($m[1], "...


2

I have registered the following menus in my functions.php Note that register_nav_menus() which uses register_nav_menu() (note the singular "menu") does not register or create a navigation menu; it only registers navigation menu locations which you can assign one or more (navigation) menus to, and for displaying the menus assigned to a specific ...


0

Three things to check: Have you added add_theme_support('post-thumbnails');? Is the uploaded image larger than 2880px x 2880px? Are you already regenerate all the thumbnails, including the existing?. Referring to the second, if the image is not "suitable" for the size, WordPress won't make the thumbnail, because it can't. For instance, if you ...


0

Now I've seen your code, I think the reviewer is wrong: they're talking about the form in agg-as-options.php, which is handled the way I describe below except they're wrong: the form is processed in the agg_options function, not outside of a function as they say this is only shown and processed on the admin aggregate-options page, i.e. only for admin users ...


0

No, there's no need to use wp_set_current_user(). I was wondering how to fire wp_head action if single post by certain users (either by user ID or username)? You can use $post->post_author to get the ID of the author of the post, and put the user ID list in an array, then just do in_array() to check if the author ID is in the ID list. For example: ...


1

There are several problems with your function. For example, $tablename points to a table that does not exist. And you don't need it anyway. If you are trying to create a new user if that email does not exist then try this: function register_user() { global $wpdb; $name = $_POST['name']; $email = $_POST['email']; $password = $_POST['...


0

The PAGEID is available in $item->object_id, if $item->object is page. $item->object contains the type of the menu item. Possible values are page,post,category,... $item->object_id contains the ID for the object. I found out this by var_dump($item) on WordPress 5.4.2.


0

I don't think Wordpress knows to load or run anything from your registerProcess.php file, so what I would do is leave the register_user() function in that file, and then require_once it from functions.php and do the active part of the code - the if .. register_user() inside functions.php where it will be run. (This is probably a bad way to do this, but if it ...


-1

It's a great question. There is a simple and not so clean way to go, and there is a cleaner way to go that is more complicated. Simple, dirty way to go You can declare global variables in PHP that will be available anywhere in PHP in this pageload. So for example, the first time you do the call you can say: global $store_last_order; $store_last_order = ...


0

So you want the index numbers for the posts array returned by WP_Query ? Try this: if ( $manset_posts->have_posts() ) { foreach( $manset_posts->posts as $key => $value ) { // $key is the index number for each post } }


0

As per my comment, I'm not sure why you'd want to do this, but it is possible. You would use something like this for your CSS: [class*='random-']{ color:red; font-size:12pt; } That's just your stylesheet targeting any class that starts with random-. You could change that to be whatever you want it to be, say entry- or whatever. You'll just need ...


Top 50 recent answers are included