How to get post URL in the_content filter?

You can do a conditional and return the post’s URL by using a get_the_permalink() in conjunction with is_single(): add_filter( ‘the_content’, ‘my_filter’ ); function my_filter( $content ) { // Check if we’re inside the main loop in a single post page. if ( is_single() && in_the_loop() && is_main_query() ) { return $content . get_the_permalink(); } return … Read more

wp_insert_posts keeps adding multiple pages

You can check whether the page exists or not, and create it only if it doesn’t already exist. get_page_by_title() can help you in this case: // Check if the page already exists if( ! get_page_by_title(‘My page Reql’) ) { // The page doesn’t exist, so let’s create it } Also, you might want to investigate … Read more

Passing arguments to my function with do_action and add_action is not working

You are doing the do_action before the action is add, try moving it: $name = “link”; add_shortcode($name, ‘aa_link_shortcode’); function shorcode_resources($var1) { global $post; $shortcode_found = false; if (has_shortcode($post->post_content, $var1)) { $shortcode_found = true; } if ($shortcode_found) { wp_enqueue_style(‘core’, ABS_URL . ‘/shortcode/css/flipbox.css’, false); wp_enqueue_script(‘my-js’, ABS_URL . ‘/shortcode/js/flipbox(‘ . $var1 . ‘).js’, false); } } //first we … Read more

Searching for content post

Stright from WordPress reference: https://developer.wordpress.org/reference/hooks/posts_search/#user-contributed-notes You can search by post title only with: function __search_by_title_only( $search, $wp_query ) { global $wpdb; if(empty($search)) { return $search; // skip processing – no search term in query } $q = $wp_query->query_vars; $n = !empty($q[‘exact’]) ? ” : ‘%’; $search = $searchand = ”; foreach ((array)$q[‘search_terms’] as $term) { … Read more

Logic to Print/echo a css class only for 1st post and ignore all post after 1st? [closed]

As I noted in the comments, this is more a programming language question than a WordPress Development question, and that goes for the second question, too. However, instead of adding to comment discussion and making more mistakes, I’ll write out an answer. function slider_news() { $num = 0; $args = array( ‘numberposts’ => 3 ); … Read more

The Point of Using apply_filters()

The point is to allow developers to customise aspects of your theme or plugin. When calling apply_filters() you provide a name and a value that you want developers to be able to filter. For your example: $array = apply_filters( ‘du/class/method’ array( ‘index’ => ‘value’, ‘index’ => ‘value’, ‘index’ => ‘value’, ‘index’ => ‘value’, ) ); … Read more