2016-04-18 12 views
0

WordpressでGenesisフレームワークを使用していて、URLに特定の文字列が含まれている場合、ロゴとメインメニューを変更したいと思います。たとえば、URLがhttp://example.com/testingの場合、example.comには1つのロゴとメニューが必要で、URLに「テスト」がある場合はもう1つのロゴとメニューが必要です。URLが特定の文字列を含む場合、起源Wordpressのロゴとメニューを変更するには?

I'veは、ロゴを変更するためにこれを試してみました:

function new_headerimage(){ 
    if(basename($_SERVER['REQUEST_URI']) == 'testing') { 
     echo '<div class="testing-header"><a href="http://example.com/testing"><img src="http://example.com/wp-content/uploads/2016/04/logotest.jpeg" alt="logo image" /></a></div>'; 
    } else { 
     echo '<div class="original-header"><a href="http://example.com/"><img src="http://example.com/wp-content/uploads/2016/04/logotest2.jpeg" alt="logo" /></a></div>'; 
}} 
add_action('genesis_header', 'new_headerimage'); 

しかし、それだけexample.com/testing/test2をexample.com/testingしていないで、新しいロゴが表示されます。任意のヒントは、URLに "testing"という単語が含まれているかどうか検索するだけでなく、テストがベース名である場合だけでなく、

答えて

0

function new_headerimage(){ 
     if(strpos($_SERVER['REQUEST_URI'],'testing') !== false) { 

      echo '<div class="original-header"><a href="http://example.com/"><img src="http://example.com/wp-content/uploads/2016/04/logotest2.jpeg" alt="logo" /></a></div>'; 
     } else { 

      echo '<div class="testing-header"><a href="http://example.com/testing"><img src="http://example.com/wp-content/uploads/2016/04/logotest.jpeg" alt="logo image" /></a></div>'; 

    } 
} 
add_action('genesis_header', 'new_headerimage'); 
を次のように試してみてください
関連する問題