• Hello friends

    i add new code tag for making new beautiful codebox, it is in function.php:

    function codequote( $atts, $content = null ) {
    	extract(shortcode_atts(array(
    		'float' => 'none',
    	), $atts));
       return '<style type="text/css">
           .codequote{
            ...;}
            .codequote:after{
            ...;}
            a:hover{...;}
    		</style>
    <div class="codequote ' . $float . '">' . $content . '</div>';
    }
    add_shortcode('code', 'codequote');

    then it executes and shows error message “syntax error, unexpected T_CONSTANT_ENCAPSED_STRING(line number to <div class=”codequote…..</div>’;)”

    can someone help me to solve it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Post all of that ‘return’ statement. My guess is that you are breaking out of the string somewhere in there.

    Also, ‘style’ tags are supposed to be in the ‘head’ of the document, not the body. Processing this inside a shortcode is going to put it in the ‘body’. You really ought to be constructing an inline style attribute:

    <div style=" your-style-rules " > ... </div>
    Thread Starter jackitshot

    (@jackitshot)

    Thank s_ha_dum very much. good suggest.

    I also would like to add new css style in header.php after head tag, if it’s only in style.css, it may not be applied to whole html. I give Function code tag up temporarily.

    …if it’s only in style.css, it may not be applied to whole html.

    That isn’t correct. Perhaps you mis-spoke? It is more the opposite. You would insert into header.php only if you do not want the rule to apply to the whole site.

    You can use the wp_head filter to insert your information into in header.php, or, if your theme is constructed correctly, you should be able to.

    Thread Starter jackitshot

    (@jackitshot)

    Because new style CSS code I put in header.php is too long, so i should creat another *.css separated from offical style.css and add link=*.css in header.php, can it avoid style.css affect to new *.css which just applies to special place?

    I really don’t understand what you just wrote.

    Unless you load the CSS files via a conditional of some sort, you are probably better off with one file vs. many. You certainly don’t want more than a few css files, and since many plugins load their own stylesheets that can be hard to accomplish.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Function new code tag to style css’ is closed to new replies.