I would like to know how I can modify the menu title within the template.php of the theme I am using.
So far, I have been able to modify both the UL and LI elements by using hooks: THEME-NAME_menu_tree__MENU-NAME and THEME-NAME_menu_link__MENU-NAME respectively. However, I cannot access the menu title form either of those (or at least that's what I think). I have tried to use the THEME-NAME_menu__MENU-NAME hook, but it seems that the function is simply being ignored.
Thank you for your time.
Your menu is generated within a block. You should be able to change the subject / title by preprocessing the block. For example, change all subjects of blocks and wrap a <span> around it.
function MYTHEME_preprocess_block(&$variables) {
$block = $variables['block'];
$block->subject = sprintf('<span>%s</span>', $block->subject);
}
Related
Is it possible add a filter to a hook after an HTML element thats after the hook?
Example Template file:
do_action('hook_before_logo'); ?>
<a id="logo></a>
** location i want add content **
Or is it possible to add an element around the <a id='logo'></a> ? Like: <div class="logo_container"><a id='logo'></a></div>
The short answer is "no". Hooks run at the place that the developer decided to place them. Any code before them, unless "someone somehow" stashed things in global scope, is not available to the hook, and anything after will not have happened yet.
If you have access to the theme, however, you can just move the hook or create a new one.
You could also do this with JS:
document
.querySelectorAll('#logo')
.forEach(
(thing) => {
const wrapper = document.createElement('div');
wrapper.classList.add('logo_container');
thing.parentNode.appendChild(wrapper);
wrapper.appendChild(thing);
}
);
(Pedantic note, I'm using QSA with an ID in order to simplify the code.)
Depending on your theme, you could also just do display: none on the logo and write your own HTML in the hook_before_logo hook.
I'm using Genesis framework and I have this page (http://staging.seedcreativeacademy.co.uk/short-courses/) showing the categories of my custom post type short_courses. I have changed the category name to course_type, by creating a new custom taxonomy.
This is how I want it to work so far (styling needs sorting out admittedly!) Im also using CPT UI plugin.
Now, when I click through to a category, is displays each 'Course in a nice masonry block as you will see here: http://staging.seedcreativeacademy.co.uk/course_type/digital-marketing/
However, I dont want this pages to look like this and I've tried adding custom template for the following:
Archive-short_courses.php & taxonomy-short_courses.php
Archive-course_type.php & taxonomy-course_type.php
But it doesnt seem to alter the layout at all...
Once I pass this hurdle I will want to alter the single.php page for these short courses, but I thought I would start with this first.
Im not sure if genesis blocks this and sets a site wide default? I know if sets a site wide default for the archive settings but I cant find anything about a template, plus i dont know if I shoujld be searching for tutorials on archive.php pages, category.php pager or taxonomy.php pages...
Can someone help me clarify things please?
course_type is a term name, not taxonomy name.
So, these are correct for your case:
category-course_type.php (category-{slug}.php is correct format. So check if course_type is correct slug of that category)
single-short_courses.php
Just in case, try reload permalinks via Settings->permalinks->save after making these changes.
Looks like your theme or some plugin is adding masnory class to body tag, which then is styled by your child theme. You need to filter that class out of your body tag and then might styling goes to non-masonary styling.
Add following code to your taxonomy-course_type.php file, and also make sure you have genesis(); call as the last thing in the template.
add_filter('body_class', 'remove_body_class', 20, 2);
function remove_body_class($wp_classes)
{
foreach($wp_classes as $key => $value)
{
if ($value == 'masonry') unset($wp_classes[$key]);
}
return $wp_classes;
}
Above could should be in custom taxonomy template, which also have genesis(); as last line.
I have a plugin and I need to correctly include inline css in WordPress using wp_add_inline_style() function. There is not problem to include CSS using this function in plugin, it works fine. But I have shortcodes that generates Custom CSS (different for different shortcode). For example I have shortcode that add text title with custom color to page (I generated unique CSS class name for this title DIV and add corresponding styles).
For example:
[mytitle text="Title example" color="#666666"]
And I have css that I need to inline:
.mytitle-id-4324324 h1 { color:#666666; }
As you see I can have multiple shortcodes on the same page, with different colors inside. The problem that if I use wp_add_inline_style function in shortcode it never not work. It should be inlined in "wp_enqueue_scripts" action, that does not triggered in right time from shortcode as I understand (because shortcodes loaded by WordPress AFTER wp_enqueue_scripts, when WordPress generate content). How to resolve this?
Note: I know that I can add inline CSS in HTML code or echo and it works, but I does not need this. My question how to get this work with wp_enqueue_scripts()?
As I understand I need to get one big global custom CSS from entire page shortcodes somehow, and then send it to some function that will include this big custom css for this page. But how to do this because shortcodes defenitions executed after including CSS by WordPress?
Example code for my shortcode:
function mgt_shortcode_header_block_wp($atts, $sc_content = null) {
.. some code here where shortcode show HTML output and generate custom css
}
add_shortcode("mgt_header_block_wp", "mgt_shortcode_header_block_wp");
How I can add inline custom css from shortcode? I can't do this inside shortcode (because its will not be called in wp_enqueue_scripts action) and I can't add some function after this function, because - custom css variable available only inside shortcode (I can't make it global var, because this is not good to use global vars here), I understand that I may need to pass it to some function from shortcode, something like:
function mgt_shortcode_header_block_wp($atts, $sc_content = null) {
.. some code here where shortcode show HTML output and generate custom css
mgt_add_to_inline_styles($custom_css); // how should work this function to correctly add inline styles passed to it?
}
add_shortcode("mgt_header_block_wp", "mgt_shortcode_header_block_wp");
But this will not work, because mgt_add_to_inline_styles() function will be executed only when this shortcode will be used on page in content, and this will be AFTER wp_enqueue_scripts action in any case, even if I will try to add mgt_add_to_inline_styles() to wp_enqueue_scripts action somewhere somehow.
So from my example I does not understand what code should be inside mgt_add_to_inline_styles() function to make it work correctly?
I'm running Wordpress 4.1 with the TinyMCE editor. In the TinyMCE editor, I've enabled the Advanced Lists plugin, which allows customizing the list style type of list items (ex. <li style="list-style-type: lower-alpha">).
When I submit a post with a modified list style, the list-style-type declaration gets stripped out, but other CSS declarations are just fine (ex. text-align).
Looking at the Wordpress source, the CSS is being filtered by the safecss_filter_attr() function in kses.php. In safecss_filter_attr() I can see an array of CSS declarations. If I add list-style-type to that array, I can then save my post, and list-style-type is no longer filtered out.
However, editing the Wordpress source isn't maintainable, as it'll eventually be overwritten when Wordpress is upgraded. So, my question is this: How do I prevent Wordpress from filtering out the list-style-type CSS declaration in a maintainable fashion?
That array you are editing is actually being passed as a parameter to the 'safe_style_css' filter. The return value of 'safe_style_css' is being stored in $allowed_attr. (Line 1482 in kses.php)
So in your functions.php, write a function that looks something like this.
function my_css_allow($allowed_attr) {
if (!is_array($allowed_attr)) {
$allowed_attr = array();
}
$allowed_attr[] = 'list-style-type';
return $allowed_attr;
}
add_filter('safe_style_css','my_css_allow');
I've not tested that but it looks like it should work.
HTH,
=C=
I want to display certain text in all my posts except if it's in this one category. How do I do that? Oh yea I almost forgot I want to include the title of the post in the text. So I think I need to use echo, cat='-5', and or something?? I don't know how to form it though. Thanks!
You could use the Wordpress function in_category(). When you use it inside the loop, it returns true if the current post is a member of the category you passed it.
<?php
if ( in_category('my-category'))
{
// don't output text
} else {
// do output text
}
?>
Do you require the text to be completely locked away, or just hidden from view? If you only need it hidden from view (but accessible to anyone who chooses to pry) then you may be able to do it very quickly using css.
If you have coded your theme - or are using someone else's - that adds helpful styles into the header, you may have a lot to work with already. For example, this is a body declaration generated by the Thematic theme:
<body class="wordpress y2011 m01 d31 h12 archive category category-orthopaedics">
Say you have a chunk of content to hide:
<div class="text_to_hide">This is what gets hidden.</div>
Then you declare the CSS as:
.category-orthopaedics .text_to_hide { display: none; }