Php 将类添加到wordpress submit_按钮
有没有一种方法可以将“类”添加到这一行中,使其符合我的CSS样式表中的.button样式Php 将类添加到wordpress submit_按钮,php,css,wordpress,submit-button,Php,Css,Wordpress,Submit Button,有没有一种方法可以将“类”添加到这一行中,使其符合我的CSS样式表中的.button样式 <?php submit_button(__('Update Profile')); ?> 谢谢 这应该可以工作:)您可以在此处查看submit_button()的参数: 如您所见,默认类应该是“primary”。我不知道Wordpress是否需要,否则我想你可以试试: <?php submit_button(__('Update Profile', 'button primar
<?php submit_button(__('Update Profile')); ?>
谢谢
这应该可以工作:)您可以在此处查看submit_button()的参数:
如您所见,默认类应该是“primary”。我不知道Wordpress是否需要,否则我想你可以试试:
<?php submit_button(__('Update Profile', 'button primary')); ?>
您只需像这样添加您的类:
submit_button( __('Update Profile'), 'my-custom-class' );
submit\u button()
是一个核心管理实用程序函数。它是构成WordPress管理主题的众多元素之一,并且应该不设置样式,因此当WP核心开发人员决定更改管理主题时,它将优雅地更改
但是,如果您真的想设置特定按钮的样式,我建议您:为按钮添加一个名为数据样式的自定义属性:
<?php
$attributes = array( 'data-style' => 'custom' );
submit_button ( 'Update Profile', 'primary', 'submit', true, $attributes );
?>
更新:让我仔细看了一下,并意识到($type
)可以安全地用于向任何WP admin按钮添加自定义类。简单到:
submit_button ( 'Update Profile', 'custom-class' );
请注意(根据功能参考),您的按钮仍将具有默认的按钮
类。这应该起作用:
.button.custom-class {
/* styles here */
}
更新2:
我已经做了更多的测试,很明显,该函数的工作原理与宣传的一样。实际产量
submit_button(__('Update Stuff'), "custom-class");
是:
例如,将此添加到仪表板CSS会更改“我的按钮”的外观,而不会影响其他按钮:
.wp-core-ui .button.custom-class {
background-color: #272727;
border-color: #666;
color: #ddd;
}
.wp-core-ui .button.custom-class:hover {
background: #212121;
border-color: #666;
color: white;
}
让它看起来像这样:
请注意,.custom class
规则将被.wp core ui.button
(wp Admin中按钮的默认选择器)设置的任何规则覆盖。您能显示此代码将生成的html吗?提交按钮不是本机PHP。您在哪里使用此代码?为什么不在HTML文件中设置按钮的样式?@HebleV她/他需要使用Wordpress中的submit_按钮
“$type(string)(可选)按钮的类型和CSS类。核心值包括“primary”、“secondary”、“delete”。默认的“primary”默认值:“primary”。请阅读此处:注意:$type可以是单个值、以空格分隔的值列表或值数组。这些值决定了按钮的HTML类。“我知道你在说什么-primary应该已经将“primary button”和“button”设置为类,但我回答了如何将自定义类添加到submit_button函数中的问题;)”任何其他类型值“foo”都会使类成为“foo”“很好的解决办法。这是可行的,不需要类。这很好,但不是问题的答案。他想添加类的原因是设计按钮的样式,而不是给它一个唯一的标识。我想我提供了方法,因为向这个类型的核心元素添加类不是直接的。这可能是正确的,但是考虑将来对这个问题的引用。作为问题标题,没有描述你的评论好吧,所以@AndreiGheorghiu你的方法奏效了……有点……我添加了你的代码,它将按钮放大了两倍,使它比其他按钮高出了2倍左右。。。它没有添加任何类型的CSS样式。。。。当我尝试添加样式时,没有任何更改。。。即使在之后添加了“!important”以覆盖其他内容。。。。说得对,$type
接受自定义类。这是向WP admin按钮添加类的正确方法。
submit_button(__('Update Stuff'), "custom-class");
<p class="submit">
<input type="submit"
name="submit"
id="submit"
class="button custom-class"
value="Update Stuff">
</p>
.wp-core-ui .button.custom-class {
/* normal state rules here */
}
.wp-core-ui .button.custom-class:hover {
/* hover state rules here */
}
.wp-core-ui .button.custom-class:focus,
.wp-core-ui .button-custom-class:active {
/* active/focus state rules here */
}
.wp-core-ui .button.custom-class {
background-color: #272727;
border-color: #666;
color: #ddd;
}
.wp-core-ui .button.custom-class:hover {
background: #212121;
border-color: #666;
color: white;
}