Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

You can use somthing like this: function my_custom_shortcode( $atts ) { // Attributes $atts = shortcode_atts( array( 'word' => 'example', // the word which will be replaced 'part' => '1' // for identifing the different texts ), $atts, 'textblock' ); // only if a word exists ...


0

but how does this work without even a call to "the_post()" Template tags like the_title(), the_content() etc., as well as the ACF get_field() functions, all use the global $post variable to determine which post's title, content etc. to display (unless a specific ID is specified). When a WordPress page is loaded, WordPress performs the "main" query, which ...


0

I think you have to pass post ID parameter in the get_field() if you get data using loop. so pass the in the get_field(). because currently it is trying to get data from current page field. Try this if it works : if( get_field( 'video_link', get_the_id() ) ) { get_field( 'video_link', get_the_id() ); } else { if( has_post_thumbnail( ...


0

The solution I'm looking for is for a specific taxonomy item to be the default/priority in case it's ticked with other taxonomy items Are you actually looking for something like this: $default_slug = 'taxonomy_z'; // slug of the default term if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { $list = wp_list_filter( $terms, array( 'slug' =&...


-1

ACF saves the created field in the database for a specific post, taxonomy, etc. And this can be displayed anywhere using the ID and without a loop. If this is a separate template for a specific page, then this is normal. Especially with ACF. If this is done for the entire template via "page.php", then this creates problems with site administration in the ...


3

You should be able to change create_function( '$a', "return null;" ) to Anonymous Function (aka Closure) : From : add_theme_page( $this->args['page_slug'], __('Dev Mode Info', 'nhp-opts'), __('Dev Mode Info', 'nhp-opts'), $this->args['page_cap'], $this->args['page_slug'].'&tab=...


4

There is an inbuilt function for returning null: __return_null. So you can replace create_function('$a', 'return null;'); with just '__return_null' (note the quotes) as it seems $a is not used anyway. Or you can use an anonymous function as the argument directly: function($a) {return null;} (no quotes). Either way since the argument is expecting a ...


1

You could use the wp_get_nav_menu_items filter add_filter('wp_get_nav_menu_items', 'prefix_add_categories_to_menu', 10, 3); Then you could do something like this: function prefix_add_categories_to_menu($items, $menu, $args) { // Make sure we only run the code on the applicable menu if($menu->slug !== 'replace_this' || is_admin()) return $items; ...


0

I was getting the same fatal error after creating a similar dynamic menu. What fixed the issue for me was redefining the default values: $post->target = ''; $post->attr_title = ''; $post->description = ''; $post->classes = ''; $post->xfn = ''; $post->status = 'publish'; $post->original_title = ''; So your foreach loop would look like ...


0

You want to use admin-post.php or admin-ajax.php (AJAX only) to allow your front-end form to interact with WordPress. Setting this up will allow you to create an action where you use the $_POST array to find the content you're looking for with WP_Query and print it out as the response to your request. Here's a decent guide to both methods: https://...


0

The only solution that worked for me happens to add an action filter to functions.php in the following format: add_action('pre_get_posts', function($q){ if (is_category()){ if(is_category('NEWS')): $q->set( 'posts_per_page', 2 ); endif; } });


0

Usually when search results pull a page's content into a section for an excerpt, it runs the content through a filter which runs strip_tags or some equivalent WordPress specific function that removes any and all HTML tags so as to not break the site due to a opening <div> tag not having a closing partner because the excerpt cut off the ending before it ...


-1

You can use Advanced Access Manager Plugin https://wordpress.org/plugins/advanced-access-manager/ works user level based capabilities from wp-admin dashboard it's works woocommerce also.


0

Modifying the editor role by adding new capabilities will grant users editor capabilities plus these new capabilities. As long as you're comfortable with that level of access, there aren't additional security concerns. If you want to create a new role which is what I recommend for this scenario, you can craft the capabilities according to your needs and ...


0

They're not directly really related, and do different things, except for a couple of situations. The Customization API is a way of registering settings and controls in the Customizer, and is very flexible. You can use it to add controls for just about anything in your theme. add_theme_support(), on the other hand, lets your theme tell WordPress (or plugins)...


0

<?php error_reporting(0); $doc = new DOMDocument(); $doc->loadHTMLFile('http://example.com/wp-content/themes/theme_name/myoutsidermenu.php'); echo $doc->saveHTML(); ?> note, I added the removal of error reporting as this above method output warnings when pulling data across domains.


1

I believe the most direct way of customizing WordPress feeds is to hook into them directly with the following filter. Edit: as we talked about, let's just edit the content to tear out any function edit_your_feed_content($content) { $content = preg_replace("/(<figure.*?[^>]*>)(.*?)(<\/figure>)/i", "", $content); return $content; } ...


0

You can achieve this using filter provided in Astra: add_filter( 'astra_has_custom_logo', '__return_false' ); The above filter disables logo on the website. You will have to add this filter in your child theme's functions.php file inside if conditions of pages where you want to hide the logo.


-1

I could be wrong but I don't think there's an easy way to modify these fields generally, you'd probably need to use a bit of JavaScript in the admin to manipulate the field when the page loads to change it from an input to textarea. I've not tested this, but something like this in jQuery might work if triggered on page load: $( '#blogdescription' )....


0

Following @nmr's comment, you can try this: if( is_user_logged_in() ) { global $current_user; echo 'Hello, ' . esc_html( $current_user->display_name ); }


0

The number in the above example are not indicative of a need for a custom database table solution, the database will be fine with just using the users table for the users, posts table for the posts and usermeta table for the link between users and posts. Its hard to offer a more definitive answer without knowing a little more about what the needs of the ...


0

İ found a solution: $posts = get_queried_object(); echo $posts->count;


0

Finally i had create a taxonomy with name manufacturers and an attribute with the same name. This may caused a confict (i didn't find out more!). So i create an attribute with name brands and i use this for my custom query.


1

You can create a shortcode function to use in your content eg. [data-display] which you would place in your custom plugin, child theme's functions.php, or /wp-content/mu-plugins/ folder: add_shortcode('data-display', 'custom_api_data_display'); function custom_api_data_display($atts) { // for whatever you API call function is // you may want check $...


0

The Solution is in the Document root of your subdomain. You must set it to "public_html/wp-content" because it also loads your themes' files which are outside the uploads directory


0

If your theme is called my-theme the configuration is stored as serialized PHP object in a option name called theme_mods_my-theme in the wp_options table in your Wordpress database. Use any Database editor tool to execute the query: SELECT * FROM `wp_options` WHERE `option_name` LIKE 'theme_mods_%' with will return all the customizations for every theme ...


1

WooCommerce has already a Geo IP feature that you can use through WC_Geolocation Class. I have revisited completely your code. To target a product category you can use WordPress has_term() function on WooCommerce Product Category custom taxonomy as follow: function is_geo_country_belgium() { // Get an instance of the WC_Geolocation object class $...


1

If you use native editor (and not some PageBuilder that stores data in its way), then you should be able to use the_content filter to do that: add_filter( 'the_content', 'my_the_content_filter' ); function my_the_content_filter( $content ) { $content = str_replace(...); return $content; } You might put some conditions in there, to check if you ...


0

For achieve this title you need to extend get_the_archive_title . here is how or check the official doc function wpse64458_get_the_archive_title($title){ if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } return $title; } add_filter( '...


0

This happens because on every page load you call remove_role As the docs note: When a role is removed, the users who have this role lose all rights on the site. Roles are not like post types, they exist in the database, and removing/adding a role updates the database. For that reason you shouldn't add them on every page load, it's better to do it on ...


0

You can use get_the_category_list(), which returns a list of categories assigned to the post (each category in the list links to the category archive): printf( '<span class="posted-on">last updated on %1$s</span><span class="byline"> <i class="fa fa-user"></i> %2$s</span> in %3$s', sprintf( '<a href="%1$...


Top 50 recent answers are included