Articles of functions

Sanitize slug title

i need to convert this strings into the post url: (numbers with the point and € symbol) ex: 9.000€ -> 9000-euro I found this function but is not working: add_filter( ‘sanitize_title’, ‘sanitize_title_extra’ ); function sanitize_title_extra( $title ) { $friendlyURL = htmlentities($title, ENT_COMPAT, “UTF-8”, false); $friendlyURL = preg_replace(‘/&([a-z]{1,2}) (?:acute|lig|grave|ring|tilde|uml|cedil|caron);/i’,’\1′,$friendlyURL); $friendlyURL = html_entity_decode($friendlyURL,ENT_COMPAT, “UTF-8”); $friendlyURL = preg_replace(‘/[^a-z0-9-]+/i’, […]

Child theme – overriding add_image_size by a child theme

This question already has an answer here: remove or update add_image_size 3 answers

PHP files included in functions.php don't seem to work

This is my first post on WordPress StackExchange, I’ll try to be precise. My question is: Is there anything in particular I should do to the files I’m including in my theme’s functions.php file? I’m creating a WordPress theme and my functions.php file is getting very big now. I managed to remove a lot of […]

How to target only the front page (not subsequent paginated pages) in theme/plugin?

I’d like to switch on the front page ONLY. Not subsequent paginated pages (like ?paged=2). I want to output certain output only on the “true” front page of the site. I’ve tried: <?php if (is_front_page() && get_query_var(‘paged’, 1) == 1 || 0): ?> but this only works if the paged variable is present (ex: domain.com?paged=1).

Show modified time if post is actually modified

I want to display post updated time only if post is modified, I am using function the_modified_time() . So I just read about that there is if statement that can be used to check if post is even modified that looks like this: if (get_the_modified_time() != get_the_time()) So I put this in my template where […]

How can I create a page with a specific URL?

I would like to have a few pages which can be reached by anyone who knows the URL, but which are not listed on the WordPress menu. I would like those pages to have a name rather than a number, but I don’t see a way to do any of these things. That is, I […]

My simple custom shortcode is not longer working (possibly due to upgrade to WordPress 4.4 ?)

I have a simple function in functions.php that creates a custom shortcode: function my_line_break() { return “<br>”; } add_shortcode( ‘new line’, ‘my_line_break’ ); Now, I don’t know if this happened after upgrading to 4.4 but it’s not longer working and pages just render [new line] in plain text. Anyone can help with this? I looked […]

How to add a rel attribute to images that contains their categories?

I’ve added categories to images, so that I can use them to filter images within a portfolio page. Now I’m thinking I need to add the rel attribute to each image that contains its assigned categories. Is this the right approach? If so, how do I add add rel with the applicable categories?

posts_per_page not working

For whatever reason the posts_per_page parameter isn’t working. I already called it earlier in the template and I used wp_reset_query(), yet it’s not working with the second instance. Any idea why? <div class=”new_home_single”> <ul> <?php $the_query = new WP_Query( ‘posts_per_page=6’ ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <div class=”posting_classs”> <a […]

How to properly add function called by action-hooked function to functions.php?

I am modifying my main queries with a function, modify_main_query($query), that determines which page is being accessed by the user via if/else statement, and then modifies the query accordingly. I am adding that function using this hook: The main function’s hook add_action(‘pre_get_posts’, ‘modify_main_query’) One of my if clauses (for a certain page) inside of modify_main_query($query) […]